using System; using System.Collections.Generic; using System.Security.Cryptography; using System.Web; public class Program { public static void Main() { var parameters = new Dictionary { { "bankId", "507f1f77bcf86cd799439011" }, { "amount", "500" }, { "userId", "987654" }, { "name", "Test User" }, { "userName", "testUserName" }, { "processId", "123456789" } }; var paramString = HttpUtility.ParseQueryString(string.Empty); foreach (var param in parameters) { paramString[param.Key] = param.Value; } string encodedParams = paramString.ToString(); // bankId=507f1f77bcf86cd799439011&amount=500&userId=987654&name=Test+User&userName=testUserName&processId=123456789 string key = "e59de9db1246eef0423a8c9045bdc5c9ea5729695cf792d065cac10373add831"; // Replace it with your own API Secret. string sign = CreateToken(encodedParams, key); // E2ftNgJbcRAEZfWA9Lb8SbhsB7fBS8UJZMVOwRMslr4= } static string CreateToken(string message, string secret) { secret = secret ?? ""; var encoding = new System.Text.ASCIIEncoding(); byte[] keyByte = encoding.GetBytes(secret); byte[] messageBytes = encoding.GetBytes(message); using (var hmacsha256 = new HMACSHA256(keyByte)) { byte[] hashmessage = hmacsha256.ComputeHash(messageBytes); return Convert.ToBase64String(hashmessage); } } }