如何解决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 的一部分,但请确保在测试时将其删除
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。