Bitcoin Forum
May 30, 2024, 06:35:57 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Yobit API invalid sign C#  (Read 115 times)
naviomg (OP)
Newbie
*
Offline Offline

Activity: 55
Merit: 0


View Profile
March 10, 2018, 09: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);
                }
            }
Coding Enthusiast
Legendary
*
Offline Offline

Activity: 1039
Merit: 2783


Bitcoin and C♯ Enthusiast


View Profile WWW
March 11, 2018, 11: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));

Projects List+Suggestion box
Donate: 1Q9s or bc1q
|
|
|
FinderOuter(0.19.1)Ann-git
Denovo(0.7.0)Ann-git
Bitcoin.Net(0.26.0)Ann-git
|
|
|
BitcoinTransactionTool(0.11.0)Ann-git
WatchOnlyBitcoinWallet(3.2.1)Ann-git
SharpPusher(0.12.0)Ann-git
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!