using System.Security.Cryptography;
static string apiPublicKey = "API_PUBLIC_KEY";
static string apiPrivateKey = Base64EncodeString("some_api_key_1234");
static string endPoint = "https://www.website.com/getToken";
public static void Main()
Console.WriteLine("API-Sign: '{0}'", GenApiSign());
static private string GenApiSign()
string ApiNonce = "1586096626919";
Console.WriteLine("API nonce: {0}", ApiNonce);
Console.WriteLine("API_PRIVATE_KEY: '{0}'", apiPrivateKey);
byte[] ApiNonceBytes = Encoding.Default.GetBytes(ApiNonce);
byte[] h256Dig = GenerateSHA256(CombineBytes(ApiNonceBytes, Encoding.Default.GetBytes("nonce="), ApiNonceBytes));
byte[] h256Token = CombineBytes(Encoding.Default.GetBytes("/getToken"), h256Dig);
string ApiSign = Base64Encode(GenerateSHA512(Base64Decode(apiPrivateKey), h256Token));
public static byte[] CombineBytes(byte[] first, byte[] second)
byte[] ret = new byte[first.Length + second.Length];
Buffer.BlockCopy(first, 0, ret, 0, first.Length);
Buffer.BlockCopy(second, 0, ret, first.Length, second.Length);
public static byte[] CombineBytes(byte[] first, byte[] second, byte[] third)
byte[] ret = new byte[first.Length + second.Length + third.Length];
Buffer.BlockCopy(first, 0, ret, 0, first.Length);
Buffer.BlockCopy(second, 0, ret, first.Length, second.Length);
Buffer.BlockCopy(third, 0, ret, first.Length + second.Length,
public static byte[] GenerateSHA256(byte[] bytes)
SHA256 sha256 = SHA256Managed.Create();
return sha256.ComputeHash(bytes);
public static byte[] GenerateSHA512(byte[] key, byte[] bytes)
var hash = new HMACSHA512(key);
var result = hash.ComputeHash(bytes);
public static string Base64EncodeString(string plainText)
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
return System.Convert.ToBase64String(plainTextBytes);
public static string Base64Encode(byte[] bytes)
return System.Convert.ToBase64String(bytes);
public static byte[] Base64Decode(string base64EncodedData)
var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);
return base64EncodedBytes;