V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Livid
267.12D
572.87D
V2EX  ›  OpenResty

OpenResty 中有 openssl_sign() 的实现么?

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

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

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