· 8 years ago · Dec 06, 2017, 02:36 PM
1UserId – account userid assigned by Madison Logic for accessing the API
2RequestTimestamp – current date time in string representation
3SecretKey – account secret key assigned by Madison Logic for accessing the API
4
5public string BuildSignature(uint UserId, string Timestamp, string SecretKey)
6 {
7 ASCIIEncoding encoding = new ASCIIEncoding();
8 string signature = string.Empty;
9 string key = string.Format("{0:s}{1:zzzz}{2}", Timestamp, Timestamp, UserId);
10
11 byte[] skbytes = encoding.GetBytes(SecretKey); // encode the secret key
12 byte[] keybytes = encoding.GetBytes(key); // encode the key;
13
14 HMACSHA1 hmacsha1 = new HMACSHA1(skbytes); // create the encryption object with the specified encoded secret key
15 byte[] hmessage = hmacsha1.ComputeHash(keybytes); // create a hash message
16
17 signature = ByteToString(hmessage).ToLower();
18
19
20
21 return signature;
22 }
23
24protected virtual string ByteToString(byte[] buff)
25 {
26 string sbinary = "";
27
28 for (int i = 0; i < buff.Length; i++)
29 {
30 sbinary += buff[i].ToString("X2"); // hex format
31 }
32 return (sbinary);
33 }