微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在C#中验证Uber Webhook调用

如何解决如何在C#中验证Uber Webhook调用

我假设在uber webhook调用中,接收到JSON正文。使用以下代码计算Webhook主体的哈希值:

private string CalcHMACSHA256Hash(string webhookBody,string secretKey)
    {
        string result = "";
        var enc = Encoding.Default;
        byte[]
        webhookBodyBytes = enc.GetBytes(webhookBody),secretKeyBytes = enc.GetBytes(secretKey);
        System.Security.Cryptography.HMACSHA256 hasher = new System.Security.Cryptography.HMACSHA256(secretKeyBytes);
        using (HMACSHA256 hmac = new HMACSHA256(secretKeyBytes))
        {
            byte[] computedHash = hmac.ComputeHash(webhookBodyBytes);
            string k = "";
            foreach (byte test in hmac.Hash)
            {
                k += test.ToString("X2");
            }
        }
        byte[] baHashedText = hasher.ComputeHash(webhookBodyBytes);
        result = string.Join("",baHashedText.ToList().Select(b => b.ToString("x2")).ToArray());
        return result;
    }

因此我可以将其输出与标头值(即“ X-Uber-Signature”)进行匹配。但是其输出与webhook调用中的标头值不匹配。 验证超级Webhook调用的正确方法是什么?

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