using System;
using System.Security.Cryptography;
using System.Text;
public class Program
{
private static byte[] ComputeSHA512Hash(string data)
{
byte[] hash;
using (SHA512 shaM = SHA512.Create())
{
var b = Encoding.UTF8.GetBytes(data);
hash = shaM.ComputeHash(b);
}
return hash;
}
private static bool check(string serverSignature, dynamic data){
var clientSecret = "THIS IS A SECRET";
var stringToHash = $"{data.eventTime}.{data.eventId}.{clientSecret}";
var hmacResult = ComputeSHA512Hash(stringToHash);
var clientSignature = Convert.ToHexString(hmacResult);
return clientSignature == serverSignature;
}
public static void Main()
{
var requestBody = @"{
""eventType"": ""change"",
""eventTime"": ""2023-06-14 13:56:12"",
""eventId"": ""1A2AE4F6-60EE-49BC-B1E5-BCCD4D77EA6D"",
""source"": ""table"",
""sourceObject"": ""Extension_Factors""
}";
dynamic body = Newtonsoft.Json.JsonConvert.DeserializeObject(requestBody);
if (
check("3A003D142EB816099406B89D41DAA6F060885320BB9D4C8288CE46F7A78DB859A99AD34766A23476C3AB81A680997811D7FF2F15AF37DD971FEB389F063B938E", //this is what you need to check //Take from request header "X-Priceedge-Webhook-Signature"
body))
Console.WriteLine("Good signature");
else
Console.WriteLine("Bad signature");
}
}