glitch100 / BinanceDotNet

Official C# Wrapper for the Binance exchange API, with REST and WebSocket endpoints
https://www.nuget.org/packages/BinanceDotNet/
MIT License
161 stars 138 forks source link

Signature generation error with HMAC SHA256 #169

Open powerpamm opened 4 years ago

powerpamm commented 4 years ago

Issue Overview

I tried to generate signature such as in official example with the same keys but always have another result. I tried with my own key but always gen an error 401 I use C# with Class HMACSHA256 to develop my software.

May be anybody knows how to fix it???

raderag commented 4 years ago

Is your timestamp the same? Are your parameters in the same order? maybe post your code.

raderag commented 4 years ago

I think this works.

` string timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString(); string totalParams = $"timestamp={timestamp}&recvWindow=5000";

        var messageBytes = Encoding.UTF8.GetBytes(totalParams);
        var keyBytes = Encoding.UTF8.GetBytes(secret);
        var hash = new HMACSHA256(keyBytes);
        var computedHash = hash.ComputeHash(messageBytes);
        string sig =  BitConverter.ToString(computedHash).Replace("-", "").ToLower();

        Console.WriteLine(sig);`