【发布时间】:2022-01-16 11:12:47
【问题描述】:
PHP
$apiKey='1DxhT7xiQPcliOnWLO/IOf74VqwxCCohJAhf8AE4TzmyAUqPawKEOQOKBMEu3Cqnbm1DJTbNje//J8W4QqU83Zg==';
$hashValue=(hash_hmac(
'sha256',
'orgID=6197bf9239fef3001b9241c2&userIdentifier=2717&isCorporate=true',
utf8_decode($apiKey)
));
//Value is : 787a88e590659ea889a8081b35043a9a5fb092af7e69736920c96109dc511182
JS
const CryptoJS = require('crypto-js');
const secret = 'DxhT7xiQPcliOnWLO/IOf74VqwxCCohJAhf8AE4TzmyAUqPawKEOQOKBMEu3Cqnbm1DJTbNje//J8W4QqU83Zg==';
const hmac = CryptoJS.HmacSHA256(
'orgID=6197bf9239fef3001b9241c2&userIdentifier=2717&isCorporate=true',
secret
);
const hash = hmac.toString(CryptoJS.enc.Hex); //_HMAC_Hash_asHex_
console.log(hash);
//Value is : 2f577ba975be5f76df586f5536bf9c0ae8328a90de2a60d8be8bef29aea5f4c5
【问题讨论】:
-
您的
$apiKey和secret值不匹配。 -
您的
$apiKey与secret不匹配:$apiKey='1DxhT7...与secret = 'DxhT7...。此外,utf8_decode在那里完全没有意义。
标签: php node.js sha256 cryptojs hmac