【发布时间】:2015-12-31 03:59:56
【问题描述】:
我正在使用 Mandrill 入站 Webhook 调用 WCF API 中的方法。请求通过,我可以成功解析等。
我的问题在于获取 X-Mandrill-Signature 标头的值以匹配我正在生成的签名(基于此处详述的过程:https://mandrill.zendesk.com/hc/en-us/articles/205583257-Authenticating-webhook-requests)。
这是我目前正在做的事情:
List<string> keys = HttpContext.Current.Request.Params.AllKeys.ToList();
keys.Sort();
string url = "MyMandrillWebhookURL";
string MandrillKey = "MyMandrillWebhookKey"
foreach (var key in keys)
{
url += key;
url += HttpContext.Current.Request.Params[key];
}
byte[] byteKey = System.Text.Encoding.ASCII.GetBytes(MandrillKey);
byte[] byteValue = System.Text.Encoding.ASCII.GetBytes(url);
HMACSHA1 myhmacsha1 = new HMACSHA1(byteKey);
byte[] hashValue = myhmacsha1.ComputeHash(byteValue);
string generatedSignature = Convert.ToBase64String(hashValue);
而generatedSignature 的值与X-Mandrill-Signature 的值不匹配
我知道 Mandrill 文档表明编码需要以二进制而不是十六进制进行(我认为我的代码可以做到这一点,但如果我错了,请纠正我),但是,除此之外我无法做到我的问题是正面还是反面。非常感谢任何帮助。
【问题讨论】:
标签: c# .net wcf mandrill webhooks