【发布时间】:2020-11-27 05:16:55
【问题描述】:
我正在使用Bold Commerce Webhooks 订阅我商店中的订阅事件。他们提供了有关如何在 PHP 中生成请求签名的文档:
$now = time(); // current unix timestamp
$json = json_encode($payload, JSON_FORCE_OBJECT);
$signature = hash_hmac('sha256', $now.'.'.$json, $signingKey);
我正在尝试在 node.js 中重新创建我这边的哈希。根据我的研究,到目前为止,我已经得出以下结论,我认为这非常接近,但还不匹配:
const hash = request.header("X-Bold-Signature")!;
const SECRET = "my-secret-api-key";
const body = request.body;
const time = request.header("timestamp")!;
const mySignature = crypto.createHmac('sha256', SECRET).update(time + '.' + body).digest("hex");
if (mySignature !== request.header("X-Bold-Signature")!) {
//...
}
我也尝试过使用 JSON.stringify(body) 更改哈希但仍然不匹配。
【问题讨论】:
标签: node.js http-headers sha256 hmac cryptojs