Signature Key Verification
.NET
using System.Security.Cryptography;
using System.Text;
var jsonMessage = "[CALLBACK MESSAGE]";
var headers = new Dictionary<string, string>()
{
{ "X-Signature", $"sha256=yu2OvBe3Gyq1Nz/4R6KO8F3KpGCuW7VhH9yUPhYtNRU="},
{ "X-Signature-Timestamp", "1762181943494" }
};
var signature = headers.GetValueOrDefault("X-Signature")!["sha256=".Length..];
var signatureKey = "4cde378d-43b6-405f-94aa-55c010d4d42a";
var unixTimeMilliseconds = headers.GetValueOrDefault("X-Signature-Timestamp");
string message = $"{jsonMessage}.{unixTimeMilliseconds}";
using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(signatureKey));
var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(message));
var result = Convert.ToBase64String(hash);
if (result.Equals(signature))
Console.WriteLine("Signature is valid");
else
Console.WriteLine("INVALID SIGNATURE!");.PHP
node.js
Last updated