在 c# 中验证 zendesk webhook 的真实性

问题描述 投票:0回答:0

我正在尝试验证 webhook 签名以验证 webhook 签名

下面是我的 c# 代码,但它不起作用

string json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();
string signature = Request.Headers["x-zendesk-webhook-signature"];
string timestamp = Request.Headers["x-zendesk-webhook-signature-timestamp"];
            
// Signing secret from webhook itself 
string SIGNING_SECRET = "Secret key";
            
_logger.LogDebug("Zendesk signature: " + signature);
_logger.LogDebug("Zendesk timestamp: " + timestamp);
_logger.LogDebug("Zendesk body: " + json);
var b1 = timestamp + json;
string newSignature = "";

using (var hmacsha256 = new HMACSHA256(Encoding.UTF8.GetBytes(SIGNING_SECRET)))
{
    var hash = hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(b1));
    newSignature = Convert.ToBase64String(hash);
}

return signature.Equals(newSignature, StringComparison.OrdinalIgnoreCase);

我正在关注以下文档以供参考,但它在节点中

https://developer.zendesk.com/documentation/event-connectors/webhooks/verifying/#verifying-the-signature

c# webhooks zendesk
© www.soinside.com 2019 - 2024. All rights reserved.