【发布时间】:2022-02-18 13:06:00
【问题描述】:
我无法使用“crypto-js”包验证来自 shopify 的 webhook 响应。
我正在使用:“Node.js、AWS-Lambda、crypto-js”和以下代码进行验证
var CryptoJS = require("crypto-js");
var getRawBody = require("raw-body");
var Buffer = require('buffer/').Buffer // note: the trailing slash is important!
exports.handler = async (event, context) => {
let hmac = event.hmac;
const bodyString = Buffer.from(event.body, "utf8").toString();
var bodyForVerification = bodyString.replace('/\\/g', '\\\\');
let firma = CryptoJS.HmacSHA256(bodyForVerification, "****");
var hashInBase64 = CryptoJS.enc.Base64.stringify(firma);
let calculatedHmacBase = hashInBase64.toString(CryptoJS.enc.hex);
if(hmac == calculatedHmacBase {
console.log("verificado");
}
};
HMAC 不同..
【问题讨论】:
标签: node.js aws-lambda shopify shopify-api-node