【发布时间】:2022-06-28 12:47:48
【问题描述】:
我正在尝试验证来自竹子的 webhook。文档在这里https://documentation.bamboohr.com/docs/webhooks
打开标题后,我看到了这个:
- X-BambooHR-签名:362cb0eff0193af8d3f939349f84014e5c70bba4cfc105682b45ecd305db01ff
- X-BambooHR-时间戳:1652747163
这是我的代码,来自 webhook 触发的 azure 函数。 testOutput 不是“X-BambooHR-Signature”标头中的内容:
string data;
using (var reader = new StreamReader(req.Body))
{
data = await reader.ReadToEndAsync();
}
string privateKey = "<gotten from bamboohr webhookconfig>";
if (req.Headers.Keys.Contains("X-BambooHR-Signature") && req.Headers.Keys.Contains("X-BambooHR-Timestamp"))
{
string timestamp = req.Headers["X-BambooHR-Timestamp"];
string signature = req.Headers["X-BambooHR-Signature"];
byte[] privateKeyBytes = Encoding.UTF8.GetBytes(privateKey);
byte[] combinedBytes = Encoding.UTF8.GetBytes(data + timestamp);
HMACSHA256 hmac = new HMACSHA256(privateKeyBytes);
byte[] testOutputBytes = hmac.ComputeHash(combinedBytes);
string testOutput = Convert.ToBase64String(testOutputBytes);
log.LogInformation("testOutput is: " + testOutput); //----NOT EQUAL TO signature.
}
知道我可能做错了什么吗? testUutput 类似于 'llBdZd2IfVdrJBlkGFFNG2dszDxpgJlJ4vQqTATJsYU=' ,如您所见,它甚至不接近。
【问题讨论】:
标签: c# cryptography azure-functions webhooks