Search code examples
apioauthsignaturehmacsha512

please explain? api signature example


(Update: still stuck after changes made from John's comment)
I am hoping for somebody to kindly try to explain in layman's terms how the signature is generated in the following example? I am pretty much stuck at this point.. I get the same result in an online hash generator (see picture below) and in my own code; but it differs from the example in the website (also pictured below).

https://www.gate.io/docs/apiv4/en/#authentication edit: website seems only reachable through google search, direct link gives 404? So I attached the page as image, see below

Request: List all orders

GET /api/v4/futures/orders?contract=BTC_USD&status=finished&limit=50 HTTP/1.1

secret:

secret

resulting signature string (edit: updated, thanks @John Glenn)

GET\n/api/v4/futures/orders\ncontract=BTC_USD&status=finished&limit=50\ncf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e\n1541993715

(note that in the example on the website, there are line breaks for readability)

Signature generated according to the example:

eae42da914a590ddf727473aff25fc87d50b64783941061f47a3fdb92742541fc4c2c14017581b4199a1418d54471c269c03a38d788d802e2c306c37636389f0

Explanation from the website:

Signature generation method is HexEncode(HMAC_SHA512(secret, signature_string)), i.e., the hexadecimal digest output of HMAC-SHA512 with APIv4 secret as secret and signature string as message.

But if I put it into a HMAC-SHA512 generator (e.g., https://www.javainuse.com/hmac), the value I get is:

58000238bf5eef226028e108df259184f14bf3021eb27c324a808334d187da42c38f4510b30215ee9b0c05d6352396e99f67fa920079746bb4dfd70506592f6d

I suspect I am missing a very essential point but I am quite lost at this time..
thank you very much for your help!

enter image description here

enter image description here

hash result


Solution

  • Solved! The "\n" were not regular expressions but actual newlines in the example. In other words, the newlines should be entered as ascii newline character. Then I got the same result in the generator as from the website. correct result