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

前端 未结 5 1721
轮回少年
轮回少年 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:44

    This is explained in their documentation. Try this:

    var hash = CryptoJS.HmacSHA256("Message", "Secret Passphrase");
    
    var base64 = hash.toString(CryptoJS.enc.Base64);
    

    You need to include http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/enc-base64-min.js for this. If you didn't include this, CryptoJS.enc.Base64 will be undefined and fallback to the default.

    Working demo: http://jsfiddle.net/ak5Qm/

提交回复
热议问题