[removed] Equivalent of PHP's hash_hmac() with RAW BINARY output?

前端 未结 5 1602
轮回少年
轮回少年 2021-02-05 13:12

I am connecting to the Amazon Product Advertising API, and to sign my request I need to base64-encode the raw binary output of an HMAC-SHA256 hash.

In t

5条回答
  •  时光说笑
    2021-02-05 13:40

    php code

    echo base64_encode(hash_hmac('SHA1', 'shanghai', '0', true).'beijing');
    

    php output

    xvBv49PpaYvXAIfy3iOSDWNQj89iZWlqaW5n
    

    node code

    var crypto = require('crypto');
    var buf1 = crypto.createHmac("sha1", "0").update("shanghai").digest();
    var buf2 = Buffer.from('beijing');
    console.log(Buffer.concat([buf1, buf2]).toString('base64'));    
    

    node output

    xvBv49PpaYvXAIfy3iOSDWNQj89iZWlqaW5n
    

提交回复
热议问题