Livid
403.83D
551.86D
V2EX  ›  OpenResty

OpenResty 中有 openssl_sign() 的实现么?

  •  
  •   Livid ·
    PRO
    · Sep 17, 2014 · 9348 views
    This topic created in 4435 days ago, the information mentioned may be changed or developed.
    7 replies  •  2015-08-26 14:37:42 +08:00
    Livid
    Livid
    MOD
    OP
    PRO
    Sep 17, 2014
    2
    @LazyZhu 非常感谢。我试试。
    Livid
    Livid
    MOD
    OP
    PRO
    Sep 17, 2014
    3
    @LazyZhu 对这块不熟,那么理论上 openssl_sign 和 hash_hmac 如果 key,data,algo 都一样的话,结果会是一样的么?
    LazyZhu
    LazyZhu
    Sep 17, 2014
    4
    一样的。

    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模块来实现了。
    Livid
    Livid
    MOD
    OP
    PRO
    Oct 7, 2014
    6
    @LazyZhu 用代码确认了一下,ngx lua 里的 hmac_sha1 和 openssl sha1 sign 真的不是同一个东西。hmac_sha1 的输出要比 openssl sha1 sign 短很多。
    mixin
    mixin
    Aug 26, 2015
    7
    @Livid ngx_lua 里面的 hmac_sha1 和 openssl sha1sigb 是一个东西。

    hmac-sha1 的输出时二进制串,一般要转化成十六进制的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   708 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:51 · PVG 01:51 · LAX 09:51 · JFK 12:51
    ♥ Do have faith in what you're doing.