Hello,
I recently began working on integrating with the new Webhook API to subscribe to events. This is being integrated into an existing ASP.NET solution written in C#. I would like to validate webhook messages using the X-ANET-Signature header, but so far have not been able to produce a matching signature in my test setup. My code is as follows:
protected void Page_Load(object sender, EventArgs e)
{
string keytext = "MY AUTHORIZE.NET SIGNATURE KEY";
byte[] key = HexDecode(keytext);
HMACSHA512 hmacsha = new HMACSHA512(key);
byte[] hash = hmacsha.ComputeHash(Request.InputStream);
string computedHash = HashEncode(hash);
//compare with the X-ANET-Signature, they don't match
}
private static byte[] HexDecode(string hex)
{
var bytes = new byte[hex.Length / 2];
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] = byte.Parse(hex.Substring(i * 2, 2), NumberStyles.HexNumber);
}
return bytes;
}
private static string HashEncode(byte[] hash)
{
return BitConverter.ToString(hash).Replace("-", "").ToLower();
}
Any guidance would be much appreciated!
03-06-2017 07:54 AM