Invalid signature with Bittrex API calls in C #

I am trying to access my Bittrex wallet balances through Bittrex API calls, but for some reason I am getting a response message with a message INVALID_SIGNATURE.

I use these functions to create a signature:

Getnonce

private String GetNonce()
{
    long ms = (long)((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);

    return ms.ToString();
}

GetApiSignature

private String GetApiSignature(String key, String message)
{
    using (var hmacsha512 = new HMACSHA512(Encoding.UTF8.GetBytes(key)))
    {
        hmacsha512.ComputeHash(Encoding.UTF8.GetBytes(message));
        return string.Concat(hmacsha512.Hash.Select(b => b.ToString("x2")).ToArray());
    }       
}

This is how I compile my calls:

public String ApiQuery(String requestUrl)
{

    url = new Uri(requestUrl);
    webreq = WebRequest.Create(url);

    signature = GetApiSignature(apiSecret, requestUrl);
    webreq.Headers.Add("apisign", signature );

    webresp = webreq.GetResponse();
    stream = webresp.GetResponseStream();
    strRead = new StreamReader(stream);

    String rtn = strRead.ReadToEnd();

    return rtn;
}

I get the same signature as the wrapper API python with the same url, and nonceetc., but can not access my balances. When I call, which does not require any signatures, it works fine ... Not sure what I am doing wrong with this.

+4
source share
1 answer

. , , - ( , ...).

- ASCII, UTF-8.

, :

private string genHMAC(string secret, string url)
{
    var hmac = new HMACSHA512(Encoding.ASCII.GetBytes(secret));
    var messagebyte = Encoding.ASCII.GetBytes(url);
    var hashmessage = hmac.ComputeHash(messagebyte);
    var sign = BitConverter.ToString(hashmessage).Replace("-", "");

    return sign;
}

, , .: -)

+6

All Articles