using System;
using System.Security.Cryptography;
using System.Text;
public class Program
{
public static void Main()
{
var apikey = "testApiKey";
var secretKey = "someSecretKey";
var timestamp = DateTime.UtcNow.ToString("yyyyMMddHHmmssffff");
var sign = ToMD5(apikey + ":" + secretKey + ":" + timestamp);
Console.WriteLine("api_key={0}×tamp={1}&signature={2}", apikey, timestamp, sign);
}
public static string ToMD5(string value, bool upperCase = true, string additionalString = null)
{
byte[] hash;
using (MD5 md5 = MD5.Create())
{
hash = md5.ComputeHash(Encoding.UTF8.GetBytes(value + additionalString));
}
return ToHex(hash,upperCase);
}
public static string ToHex(byte[] bytes, bool upperCase)
{
var result = new StringBuilder(bytes.Length * 2);
foreach (byte @byte in bytes)
{
result.Append(@byte.ToString(upperCase ? "X2" : "x2"));
}
return result.ToString();
}
}