【问题标题】:PHP and Javascript sha256 value not matchingPHP 和 Javascript sha256 值不匹配
【发布时间】: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

【问题讨论】:

  • 您的$apiKeysecret 值不匹配。
  • 您的 $apiKeysecret 不匹配:$apiKey='1DxhT7...secret = 'DxhT7...。此外,utf8_decode 在那里完全没有意义。

标签: php node.js sha256 cryptojs hmac


【解决方案1】:

你的 $apiKey 和const secret 不同。请检查

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-10-11
    • 2013-06-04
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多