Signature Key Verification

This section provides implementation examples for verifying the authenticity of requests using a signature key, which helps ensure the integrity and security of the received data (e.g., webhook events). The signature is usually included in the request headers and must be validated by computing a hash using a shared secret key. Below are examples in different languages.

.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