Docusign HMAC 不匹配

问题描述

m trying to authenticate the DocuSign request in my WebHook using HMAC but the generated value does not match any of the incoming Signatures.I使用与 DocuSign 文档中相同的密钥和代码

我的代码

exports.ComputeHash = function (secret,payload)
{
    var crypto = require('crypto');
    var hmac = crypto.createHmac('sha256',secret);
    hmac.write(payload);
    hmac.end();
    return hmac.read().toString('base64');
};

exports.HashIsValid = function (secret,payload,verify)
{
    const hash = module.exports.ComputeHash(secret,payload);
    console.log(hash);
    return verify === hash;
};

const isValid = exports.HashIsValid("MBbMgWXqOldxxxxxxxxxkQQkNey4","<?xml version=\"1.0\" encoding=\"utf-8\"?><DocuSignEnvelopeinformation xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.docusign.net/API/3.0\"><Envelopestatus><RecipientStatuses><RecipientStatus>.....","MdXRWHj2NuBY89kEpeD7llB+RBhTxbpHfaICfjc5GME=")

console.log(isValid);

我的负载生成的哈希是“SFK+ppxbCXOTIL9jZH6oi4vC1XBgoy16aoKrVO4IIi8="。

解决方法

我测试了这段代码并且工作正常。确保使用反斜杠转义所有 "。在我意识到我错过了一个未转义的 " 之前,我的测试失败了几次。我不确定您验证中的 ** 是否属于 SO 的一部分,但请确保在测试时将其删除