· 7 years ago · Oct 11, 2018, 08:10 PM
1 public static string SignAuthorizer(string apikey, string apisecret, string requestMethod, string endPoint, string date, string nonce)
2 {
3 string authorizeKey = apikey + ":" + nonce + ":" + HmacDigest(SignedString(requestMethod, "/v3/" + endPoint, date, nonce), apisecret );
4 return Convert.ToBase64String(Encoding.UTF8.GetBytes(authorizeKey));
5 }
6 private static string HmacDigest(string message, string secret)
7 {
8
9
10 byte[] secretKey = Encoding.ASCII.GetBytes(secret);
11 HMACSHA256 hmac = new HMACSHA256(secretKey);
12 hmac.Initialize();
13 byte[] bytes = Encoding.UTF8.GetBytes(message);
14 byte[] rawHmac = hmac.ComputeHash(bytes);
15 return Convert.ToBase64String(rawHmac);
16 }
17 private static string SignedString(string requestMethod, string apiEndpoint, string date, string nonce)
18 {
19 return requestMethod + apiEndpoint + date + nonce;
20 }
21
22 public static string GetTime()
23 {
24 string datetime = DateTime.Now.ToString("R");
25 var offset = TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow);
26
27 datetime = datetime.Replace(",", "");
28 string fixOffset = offset.ToString().Substring(0, offset.ToString().Length - 3);
29
30 string[] fixDate = datetime.Split(' ');
31 datetime = fixDate[0] + " " + fixDate[2] + " " + fixDate[1] + " " + fixDate[4] + " " + fixDate[5] + fixOffset + " " + fixDate[3];
32 return datetime;
33 }