V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Livid
V2EX  ›  OpenResty

OpenResty 中有 openssl_sign() 的实现么?

  •  
  •   Livid · 2014-09-17 22:59:25 +08:00 · 7550 次点击
    这是一个创建于 3470 天前的主题,其中的信息可能已经有所发展或是发生改变。
    7 条回复    2015-08-26 14:37:42 +08:00
    LazyZhu
        1
    LazyZhu  
       2014-09-17 23:11:36 +08:00   ❤️ 1
    Livid
        2
    Livid  
    MOD
    OP
       2014-09-17 23:13:17 +08:00
    @LazyZhu 非常感谢。我试试。
    Livid
        3
    Livid  
    MOD
    OP
       2014-09-17 23:20:06 +08:00
    @LazyZhu 对这块不熟,那么理论上 openssl_sign 和 hash_hmac 如果 key,data,algo 都一样的话,结果会是一样的么?
    LazyZhu
        4
    LazyZhu  
       2014-09-17 23:30:55 +08:00
    一样的。

    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
        5
    LazyZhu  
       2014-09-17 23:38:49 +08:00
    Livid
        6
    Livid  
    MOD
    OP
       2014-10-07 09:18:34 +08:00
    @LazyZhu 用代码确认了一下,ngx lua 里的 hmac_sha1 和 openssl sha1 sign 真的不是同一个东西。hmac_sha1 的输出要比 openssl sha1 sign 短很多。
    mixin
        7
    mixin  
       2015-08-26 14:37:42 +08:00
    @Livid ngx_lua 里面的 hmac_sha1 和 openssl sha1sigb 是一个东西。

    hmac-sha1 的输出时二进制串,一般要转化成十六进制的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5883 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 06:10 · PVG 14:10 · LAX 23:10 · JFK 02:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.