【发布时间】:2012-08-19 09:49:37
【问题描述】:
我正在连接到亚马逊产品广告 API,为了签署我的请求,我需要对 HMAC-SHA256 哈希的原始二进制输出进行 base64 编码。
在the PHP documentation for hash_hmac 中,第四个参数bool $raw_output 控制输出是原始二进制数据(真)还是小写十六进制(假)。只需将该参数设置为 true,我的程序就可以在 PHP 中运行。
但是,我现在正在尝试将其移植到 Javascript。我尝试使用 CryptoJS.HmacSHA256() 函数,但它似乎返回了小写十六进制。如何将其转换为二进制?
我根据 CryptoJS 文档尝试了以下方法,但两个输出是相同的:
var hash = CryptoJS.HmacSHA256("hello", "key");
console.log(hash.toString());
console.log(hash.toString(CryptoJS.enc.Base64));
【问题讨论】:
标签: php javascript binary base64 amazon-product-api