Last active
March 31, 2021 18:40
-
-
Save brainded/f358e05e0a3800ce8114a2ee5f8c2078 to your computer and use it in GitHub Desktop.
Virtuous Webhook Signature Verification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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