· 7 years ago · Sep 04, 2018, 09:46 AM
1var key1 = sha1(body);
2var key2 = key1 . SECRET_KEY;
3var key3 = sha1(key2);
4var signature = base64_encode(key3);
5
6static string ComputeSignature(byte[] body, byte[] secret) {
7 using (var sha1 = SHA1.Create())
8 {
9 var key1 = sha1.ComputeHash(body);
10 var key2 = key1.Concat(secret).ToArray();
11 var key3 = sha1.ComputeHash(key2);
12 return Convert.ToBase64String(key3);
13 }
14}
15
16var body = Encoding.UTF8.GetBytes(bodyAsString);
17
18private string GetHashedMessage(String _secret)
19 {
20 System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
21 byte[] keyByte = encoding.GetBytes(_secret);
22 String _message= "Your message that needs to be hashed";
23 HMACSHA1 hmacsha1 = new HMACSHA1(keyByte);
24
25 byte[] messageBytes = encoding.GetBytes(_message);
26 byte[] hashmessage = hmacsha1.ComputeHash(messageBytes);
27 return ByteToString(hashmessage).ToLower();
28 }
29
30 public string ByteToString(byte[] buff)
31 {
32 string sbinary = "";
33
34 for (int i = 0; i < buff.Length; i++)
35 {
36 sbinary += buff[i].ToString("X2"); // hex format
37 }
38 return (sbinary);
39 }