我需要将php hash_hmac转换为node.js。我找到了尝试过的类似问题和答案,但仍在收到{data:,错误:“未发送HMAC”,成功:false}
const params = {
method : "get_issues",
ts : time.toString(),
field_1_name : "id",
field_1_value : 123456,
sort : "status ASC, created DESC"
}
php:
$mac = hash_hmac("sha512", mac_build_query($params), $PRIVATE_KEY);
node.js:
let mac = crypto.createHmac("sha512", mac_build_query(params)).update(PRIVATE_KEY).digest().toString('base64') //('base64') //hex
在PHP中:
hash_hmac ( string $algo , string $data , string $key [, bool $raw_output = FALSE ] ) : string
示例:
hash_hmac($algo,$data,$key) // return hex string
在节点中:createHmac(algo, key).update(data).digest(encoding)
示例:
crypto.createHmac('sha512', key).update(data).digest('hex')