Author

Topic: Yobit API invalid sign C# (Read 137 times)

legendary
Activity: 1042
Merit: 2805
Bitcoin and C♯ Enthusiast
March 11, 2018, 06:39:24 AM
#2
Code:
using (var hmac = new HMACSHA512(Convert.FromBase64String(secret_key)))

Your secret_key is not Base64. Use ASCII it should work.
Code:
HMACSHA512 hmac = new HMACSHA512(Encoding.ASCII.GetBytes(secret_key));
newbie
Activity: 55
Merit: 0
March 10, 2018, 04:00:06 PM
#1
After trying around, thx to the nice documentation of Yobit, i finally managed to get a usefull error message back. It gives me the error: invalid sign.

Im using the code below. I already tried the solution of this post here: https://stackoverflow.com/questions/48717976/yobit-api-invalid-sign-c

Anyone an idea?

Code:
            var client = new HttpClient();
            var request = new HttpRequestMessage();
            request.Method = HttpMethod.Post;
            request.RequestUri = new Uri("https://yobit.net/tapi/");

            var nonce = (int)Math.Round(DateTime.Now.Subtract(new DateTime(2018, 1, 1)).TotalSeconds);

            string parameters = String.Format("method=getInfo&nonce=" + nonce);
            request.Content = new StringContent(parameters, Encoding.UTF8, "application/x-www-form-urlencoded");
            request.Content.Headers.Add("Key", public_key);

            using (var hmac = new HMACSHA512(Convert.FromBase64String(secret_key)))
            {
                byte[] signHash = hmac.ComputeHash(Encoding.UTF8.GetBytes(parameters));
                string sign = BitConverter.ToString(signHash).ToLower().Replace("-", string.Empty);
                request.Content.Headers.Add("Sign", sign);
            }

            using (HttpResponseMessage response = client.SendAsync(request).Result)
            {
                using (HttpContent content = response.Content)
                {
                    var bytecontent = content.ReadAsByteArrayAsync().Result;
                    var json = Encoding.UTF8.GetString(bytecontent);
                    Console.WriteLine(json);
                }
            }
Jump to: