using System.Collections.Generic;
using System.Security.Cryptography;
public const string APIKey = "";
public static void Main()
if(string.IsNullOrEmpty(APIKey))
throw new Exception("-- Set the API key above --");
var values = new Dictionary<string, string>() {
{ "x_account_id", "30139741"},
{ "x_gateway_reference", "75046068"},
{ "x_purchase_number", "75046068"},
{ "x_reference", "4211346"},
{ "x_result", "completed"},
{ "x_timestamp", "2022-02-21T04:17:46Z"},
var hmac = GenerateHmac(values);
Console.WriteLine("Generated:" + hmac);
Console.WriteLine("Expecting:8c15700cc8a269f2c64eebe94bdfe098613d839fbc1eab9b4ca949f4f0569560");
public static string GenerateHmac(IDictionary<string, string> payloadValues)
using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(APIKey));
.Where(kvp => kvp.Key != "x_signature" && kvp.Key.StartsWith("x_"))
.Select(kvp => $"{kvp.Key}{kvp.Value}")
.Aggregate((current, next) => $"{current}{next}");
Console.WriteLine(payloadSignature);
var rawHmac = hmac.ComputeHash(Encoding.UTF8.GetBytes(payloadSignature));
return BitConverter.ToString(rawHmac).Replace("-", string.Empty).ToLower();