Skip to content

Instantly share code, notes, and snippets.

@brainded
Last active March 31, 2021 18:40
Show Gist options
  • Save brainded/f358e05e0a3800ce8114a2ee5f8c2078 to your computer and use it in GitHub Desktop.
Save brainded/f358e05e0a3800ce8114a2ee5f8c2078 to your computer and use it in GitHub Desktop.
Virtuous Webhook Signature Verification
using System;
using System.Text;
using System.Security.Cryptography;
public static class WebhookUtility
{
public static bool IsVerified(string payload, string sharedSecret, string virtuousSignature)
{
byte[] valueByteArray = Encoding.UTF8.GetBytes(payload);
byte[] secretByteArray = Encoding.UTF8.GetBytes(sharedSecret);
using (var hmacSha256 = new HMACSHA256(secretByteArray))
{
var hashedValue = hmacSha256.ComputeHash(valueByteArray);
var signedPayload = Convert.ToBase64String(hashedValue);
if (signedPayload.Equals(virtuousSignature)) return true;
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment