简体   繁体   English

PHP 和 Javascript sha256 值不匹配

[英]PHP and Javascript sha256 value not matching

PHP PHP

$apiKey='1DxhT7xiQPcliOnWLO/IOf74VqwxCCohJAhf8AE4TzmyAUqPawKEOQOKBMEu3Cqnbm1DJTbNje//J8W4QqU83Zg==';
$hashValue=(hash_hmac(
    'sha256', 
    'orgID=6197bf9239fef3001b9241c2&userIdentifier=2717&isCorporate=true',
    utf8_decode($apiKey)
));
//Value is : 787a88e590659ea889a8081b35043a9a5fb092af7e69736920c96109dc511182

JS 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

Your $apiKey And const secret is different.你的 $apiKey 和const secret是不同的。 Please check请检查

$apiKey='1DxhT7xiQPcliOnWLO/IOf74VqwxCCohJAhf8AE4TzmyAUqPawKEOQOKBMEu3Cqnbm1DJTbNje//J8W4QqU83Zg==';
const secret = 'DxhT7xiQPcliOnWLO/IOf74VqwxCCohJAhf8AE4TzmyAUqPawKEOQOKBMEu3Cqnbm1DJTbNje//J8W4QqU83Zg==';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM