OpenResty 中有 openssl_sign() 的实现么?

2014 年 9 月 17 日
 Livid
http://php.net/manual/en/function.openssl-sign.php
8559 次点击
所在节点    OpenResty
7 条回复
LazyZhu
2014 年 9 月 17 日
Livid
2014 年 9 月 17 日
@LazyZhu 非常感谢。我试试。
Livid
2014 年 9 月 17 日
@LazyZhu 对这块不熟,那么理论上 openssl_sign 和 hash_hmac 如果 key,data,algo 都一样的话,结果会是一样的么?
LazyZhu
2014 年 9 月 17 日
一样的。

php的话可以这样:
$src = 'foo';
$key = 'bar';
$digest = hash_hmac('sha1', $src, $key);
echo base64_encode($digest);

还有Python的实现,只是将MD5换成SHA-1
http://en.wikipedia.org/wiki/Hash-based_message_authentication_code

目前只有hmac_sha1,其他方式的话得自己写lua模块来实现了。
LazyZhu
2014 年 9 月 17 日
Livid
2014 年 10 月 7 日
@LazyZhu 用代码确认了一下,ngx lua 里的 hmac_sha1 和 openssl sha1 sign 真的不是同一个东西。hmac_sha1 的输出要比 openssl sha1 sign 短很多。
mixin
2015 年 8 月 26 日
@Livid ngx_lua 里面的 hmac_sha1 和 openssl sha1sigb 是一个东西。

hmac-sha1 的输出时二进制串,一般要转化成十六进制的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/134078

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX