Help Call Private api

Hello
I need help

https://api.binance.com/sapi/v1/capital/config/getall?timestamp=1609384651688&signature=20764be7c63fec3e6b960c27b18f91b5370b79ef57ca0568049107539a18214a

When requesting the above url, I get the message “{“code”:-1022,“msg”:“Signature for this request is not valid.”}”

Through the Binance example I confirmed that my hmac hashing algorithm works
(When you put the sample private key and query, the same encryption key as the example appears)

Please help me I can’t fix the cause

My kotlin code generate hmac

fun getHmac(message: String,key:String): String? {
try {
val hasher = Mac.getInstance(“HmacSHA256”)
hasher.init(SecretKeySpec(key.toByteArray(), “HmacSHA256”))

    val hash = hasher.doFinal(message.toByteArray())
    return byteToString(hash)
} catch (e: NoSuchAlgorithmException) {
    e.printStackTrace()
} catch (e: InvalidKeyException) {
    e.printStackTrace()
}
return ""

}

One simple way to verify if your encryption method is working:

let’s pretend your API secret is ‘aaa’, what would you get as signature for “timestamp=1609384651688”?

Hi,
I’ve got the same problem and I’m using the same kotlin function for hash.
My result for your input data is “d040e94aa8d58cbacdc95ff3e3e8a31fac9e39b3fd4407c5694d1a3dad4e3a63”
Is my signature function correct?
Thanks.

The signature you generated is correct.

If you are encountering the same error, double check two things

  • The payload to be signed matches the query string sent to the API.
  • The API Secret used to sign is related to the API Key sent to the API.
1 Like