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