Short answer: API signature generation means building one exact string from the request, signing its bytes with a shared secret (HMAC) or a private key (RSA, Ed25519), and sending the result so the server can check it. A signature fails with a correct secret when the signed bytes differ from the bytes sent, or when the encoding, clock or host is wrong. Test your signer against a published answer, and never paste a live secret into an online tool.
Try it with a published sample key: HMAC signature generator.
A rejected signature usually means two programs signed different bytes, so this guide shows what each platform signs and how to test a signer with no account. Documents were read on 5 November 2026. Every key below is a published sample or a throwaway made for the test, and no private endpoint was called, so nothing here shows a platform accepting a live request.
This describes official documentation and does not recommend or rank a platform; availability depends on your jurisdiction and each platform's terms, and automated trading can lose money. For readers in Turkey: Article 99/A of Capital Markets Law No. 6362 treats activity by foreign crypto-asset platforms directed at Turkish residents as unauthorized, and the Capital Markets Board said on 5 August 2024 that appearing on its list of operating platforms does not mean authorization.
What is an API signature?
An API signature is a value computed from the request and a secret, which lets the server confirm who sent the request and that the signed fields did not change.
- It is not encryption. It hides nothing, and an HMAC cannot be decoded back into the message or the secret. The server recomputes it and compares.
- The API key names you; the secret proves it. The secret is used to sign and is not sent with the request.
- A timestamp or nonce limits replay, so a captured request soon stops working.
What is an HMAC signature? RFC 2104 defines HMAC as H(K XOR opad, H(K XOR ipad, text)): a hash run twice with the key mixed in.
API signature generation on six exchange APIs
All six sign a defined string but differ in what it covers, how the secret is used and how the result is encoded.
| Platform | String to sign | Algorithm and key | Encoding, location | Freshness | Published key and answer? |
|---|---|---|---|---|---|
| Binance Spot | Query string + body, no separator; non-ASCII percent-encoded first | HMAC-SHA256, which its key types page calls deprecated; RSA PKCS#1 v1.5 SHA-256; Ed25519 | Hex (HMAC) or base64 then percent-encoded; signature parameter | recvWindow, default 5,000 ms, maximum 60,000 | HMAC yes; RSA and Ed25519 no key |
| BtcTurk | Public key + millisecond stamp; body and parameters not covered | HMAC-SHA256, secret base64-decoded first | Base64; X-Signature | Within ±5 seconds of server time, per its FAQ | No |
| Bybit V5 | Timestamp + key + recv_window + query string or JSON body | HMAC-SHA256; RSA-SHA256 | Lowercase hex or base64; X-BAPI-SIGN | Default 5,000 ms; under 1,000 ms ahead | Answer printed, no secret |
| Coinbase | JWT claims naming method, host and path; body not covered | ES256; its auth page rules out Ed25519 for Coinbase App SDKs, but the coinbase-advanced-py (opens in a new tab) README recommends it | JWT; Authorization: Bearer | Expires after 2 minutes; one JWT per request | No |
| Kraken Spot | URI path + SHA-256(nonce + POST data) | HMAC-SHA512, secret base64-decoded first | Base64; API-Sign | Nonce must always increase | Yes |
| OKX | Timestamp + method + path with query + body | HMAC-SHA256, plus a passphrase header | Base64; OK-ACCESS-SIGN | Within 30 seconds; ISO 8601 UTC | No usable pair |
The last column decides how you can test. OKX's WebSocket login section shows an example secret and sign that did not reproduce each other when tested. Per-platform code is in the Bybit, Coinbase, OKX and Kraken guides, with BtcTurk in Turkish crypto exchange APIs.
API signature example: Python tested against published answers
Test the signer against a known key and a known answer, which needs no account and no network.
The HMAC signature Python code needs only the standard library; RSA and Ed25519 use cryptography. This ran on 5 November 2026 on Python 3.11.3 with cryptography 43.0.1. All keys are published test values, and the path argument is SigGen15_186-3.txt from NIST's vector archive.
import base64, hashlib, hmac, sys
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import ed25519, padding, rsa
# 1. HMAC-SHA256: RFC 4231, test case 2
mac = hmac.new(b"Jefe", b"what do ya want for nothing?", hashlib.sha256).hexdigest()
print("RFC 4231", mac == "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843")
# 2. Binance's sample, not a live key
secret = b"NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j"
query = ("symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1"
"&recvWindow=5000×tamp=1499827319559")
sig = hmac.new(secret, query.encode(), hashlib.sha256).hexdigest()
print("Binance", sig == "c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71")
# 3. Kraken's sample: SHA-256 first, then HMAC-SHA512 with a decoded secret
secret = base64.b64decode("kQH5HW/8p1uGOVjbgWA7FunAmGO8lsSUXNsu3eow76sz84Q18fWxnyRzBHCd3pd5nE9qa99HAZtuZuj6F1huXg==")
nonce, body = "1616492376594", "nonce=1616492376594&ordertype=limit&pair=XBTUSD&price=37500&type=buy&volume=1.25"
inner = hashlib.sha256((nonce + body).encode()).digest()
sig = base64.b64encode(hmac.new(secret, b"/0/private/AddOrder" + inner, hashlib.sha512).digest()).decode()
print("Kraken", sig == "4/dpxb3iT4tp/ZCVEwSnEsLxx0bqyhLpdfOpc6fn7OR8+UClSV5n9E6aSS8MPtnRfp32bAb0nmbRn6H8ndwLUQ==")
# 4. Ed25519: RFC 8032 section 7.1, TEST 2
key = ed25519.Ed25519PrivateKey.from_private_bytes(bytes.fromhex(
"4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb"))
sig = key.sign(bytes.fromhex("72"))
print("RFC 8032", sig.hex() == "92a009a9f0d4cab8720e820b5f642540a2b27b5416503f8fb3762223ebdb69da"
"085ac1e43e15996e458f3613d0f11d8c387b2eaeb4302aeeb00d291612bb0c00", len(sig), "bytes")
# 5. RSASSA-PKCS1-v1_5 with SHA-256: first 2048-bit SHA256 entry in NIST's SigGen15_186-3.txt
v, alg = {}, None
for line in open(sys.argv[1]):
name, _, value = line.partition(" = ")
if name == "SHAAlg":
alg = value.strip()
elif name in ("n", "e", "d") or (alg == "SHA256" and name in ("Msg", "S")):
v[name] = value.strip()
if alg == "SHA256" and "S" in v:
break
n, e, d = (int(v[k], 16) for k in "ned")
p, q = rsa.rsa_recover_prime_factors(n, e, d)
key = rsa.RSAPrivateNumbers(p, q, d, rsa.rsa_crt_dmp1(d, p), rsa.rsa_crt_dmq1(d, q),
rsa.rsa_crt_iqmp(p, q), rsa.RSAPublicNumbers(e, n)).private_key()
sig = key.sign(bytes.fromhex(v["Msg"]), padding.PKCS1v15(), hashes.SHA256())
print("NIST", sig.hex() == v["S"], len(sig), "bytes")Output:
RFC 4231 True
Binance True
Kraken True
RFC 8032 True 64 bytes
NIST True 256 bytesEach line compares with an answer someone else published, so True means your primitive and encoding are right, not that a platform accepts your full request: that needs a real or testnet key, not used here.
Worked example. Binance's sample signs symbol=LTCBTC&side=BUY&...×tamp=1499827319559 and gets a signature beginning c8db5682. Write the price as 0.10 and it begins 7f124c21, though the value is the same.
Why the same secret can give a rejected signature
If the secret is right, the bytes, encoding, clock or host are wrong; each change below gave a different result when tested.
import base64, hashlib, hmac, json, urllib.parse
from decimal import Decimal
import requests
SECRET = b"NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j" # Binance's sample
Q = ("symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1"
"&recvWindow=5000×tamp=1499827319559")
def hex8(text, key=SECRET):
return hmac.new(key, text.encode(), hashlib.sha256).hexdigest()[:8]
print("correct ", hex8(Q))
print("parameters sorted", hex8("&".join(sorted(Q.split("&")))))
print("price=0.10 ", hex8(Q.replace("price=0.1", "price=0.10")))
print("secret + newline ", hex8(Q, SECRET + b"\n"))
raw = hmac.new(SECRET, Q.encode(), hashlib.sha256).digest()
print("base64, not hex ", base64.b64encode(raw).decode()[:8])
body = {"category": "linear", "qty": "0.1"}
signed = json.dumps(body, separators=(",", ":")).encode()
sent = requests.Request("POST", "https://example.invalid/", json=body).prepare().body
print(signed, sent, signed == sent)
print(urllib.parse.urlencode({"a": "x y"}), urllib.parse.urlencode({"a": "x y"}, quote_via=urllib.parse.quote))
print(0.00001, format(Decimal("0.00001"), "f"))Output, with requests 2.31.0:
correct c8db5682
parameters sorted 70fd3043
price=0.10 7f124c21
secret + newline f66a3235
base64, not hex yNtWglrn
b'{"category":"linear","qty":"0.1"}' b'{"category": "linear", "qty": "0.1"}' False
a=x+y a=x%20y
1e-05 0.00001| Cause | Evidence | Fix |
|---|---|---|
| Parameter order | Sorting changed c8db5682 to 70fd3043 | Sign the exact string you send |
| Re-encoding | A space became + or %20 depending on the function | Encode once, then send that string unchanged |
| JSON whitespace | The json= argument of requests sent spaces that the signed string lacked | Serialize once and pass it as data= |
| Number format | price=0.10 gave 7f124c21; Python printed 0.00001 as 1e-05 | Use decimal strings |
| Hex or base64 | The same bytes read yNtWglrn in base64 | Match the table above |
| Secret handling | A trailing newline gave f66a3235; Kraken's example fails without decoding its secret | Strip on load; decode only where documented |
| Clock drift | OKX names local timezone offset as the most common cause of error 50102 | Sync the clock; rebuild timestamp and signature on every retry |
| Wrong host | Bybit's 10003 text lists four environments; OKX's 50101 says the key does not match the current environment | Keep keys and hosts together per environment |
| Platform | Bad signature | Time or nonce |
|---|---|---|
| Binance | -1022 | -1021 |
| BtcTurk | 401 Invalid Signature | 401 Invalid Nonce |
| Bybit (opens in a new tab) | 10004 | 10002 |
| Kraken | EAPI:Invalid signature | EAPI:Invalid nonce |
| OKX | 50113 | 50102 |
Details for Binance are in Binance API error codes. Do not retry in a loop: Kraken's error page (opens in a new tab) says to fix the logic first, and that repeatedly sending a key that does not exist can lock out every key on your IP address.
HMAC vs digital signature: shared secret against key pair
With HMAC both sides hold the same secret, while with a digital signature you hold a private key and the server keeps the public one.
| Property | HMAC-SHA256 | RSA-2048 PKCS#1 v1.5 | Ed25519 | ES256 (ECDSA) |
|---|---|---|---|---|
| Output | 32 bytes | 256 bytes | 64 bytes | 64 bytes raw; 69 to 72 as DER over 200 runs |
| Same input twice | Same | Same | Same | Different, both verify |
| How to test | Compare with a published answer | Verify with the public key | ||
Strictly, an HMAC is a message authentication code, and APIs just call it a signature. MDN's page on SubtleCrypto.sign makes the practical point: the verification key must stay secret, so HMAC suits cases where signer and verifier are the same entity. Binance's key types page recommends Ed25519; that is its statement, not a ranking here.
A conflict in Binance's Ed25519 samples
Do not test Ed25519 code against the Ed25519 samples in Binance's REST documentation, because they cannot be Ed25519 output.
- Size. The two samples in the Ed25519 section of
rest-api.mdand the developer site (opens in a new tab) (last modified 26 November 2026; samples unchanged) are 343 and 344 base64 characters: 256 bytes once the first, one padding character short, is repaired. RFC 8032's signature is 64 bytes, or 88 base64 characters. - Reuse. The second sample is identical to the second RSA sample; Binance's API key types page prints an 88-character Ed25519 sample, the expected size.
- Command. With a throwaway Ed25519 key on OpenSSL 3.2.1, the documented
openssl dgst -sha256 -signprinted "Key type not supported for this operation", whileopenssl pkeyutl -sign -rawinreturned 64 bytes.
Binance publishes no private key for these samples, and the sample public keys on the key types page did not verify them when tested, so they cannot be reproduced. Its Python sample calls private_key.sign() on the payload, the right shape, but running it needs a real key and was not done. Use RFC 8032 for the primitive, then a testnet key for the full path; the Ed25519 API key guide has a reproducible Binance test.
Never paste a live secret into an online signature tool
A live secret belongs only on the machine that signs, so debug with published samples or a throwaway test key.
A page you paste into can log or send what it receives, and you cannot audit it. A key with trade permission is account access. If a live secret has been pasted anywhere, treat it as leaked: delete the key and create a new one.
- Reproduce a published answer offline with the script above.
- Log the exact string you signed, never the secret, and compare it with the bytes on the wire.
- Only then try a testnet or demo key against the matching host.
For integration work in general, see Fincode's exchange API integration page; naming a platform here does not mean Fincode integrates it or has built on it.
To step through a signature by hand, Fincode's HMAC signature generator builds the string each HMAC platform above signs and compares results in your browser. It loads a published sample key, and the rule above applies there too.
Frequently asked questions
What is an API signature?
A value computed from a request and a secret or private key, which the server checks before acting.
What is an HMAC signature, and can it be decoded?
A keyed hash of the request, defined in RFC 2104. It cannot be decoded: you recompute it and compare.
Is an online HMAC generator safe to use?
Only with published samples or a throwaway key. Never enter a live secret into any website, because you cannot verify what the page does with it.
Should I use HMAC, RSA or Ed25519 for an exchange API?
It depends on what the platform offers. With RSA or Ed25519 the private key stays with you, while HMAC means both sides hold the same secret. This guide does not rank them.
Sources
- Binance Spot API documentation: rest-api.md (signed endpoints, HMAC, RSA and Ed25519 examples; GitHub file last changed 24 November 2026, developers.binance.com copy last modified 26 November 2026) (opens in a new tab)
- Binance Spot API documentation: API key types (HMAC deprecated, sample keys) (opens in a new tab)
- BtcTurk API documentation: Authentication V1 (opens in a new tab)
- BtcTurk API documentation: FAQ (401 Invalid Signature) (opens in a new tab)
- Bybit V5 API: Integration guidance (signature rule, recv_window) (opens in a new tab)
- Coinbase Developer Documentation: API key authentication (JWT, ES256) (opens in a new tab)
- Kraken: Spot REST authentication (API-Sign example) (opens in a new tab)
- OKX API v5 documentation: REST authentication, WebSocket login, error codes (opens in a new tab)
- RFC 2104: HMAC: Keyed-Hashing for Message Authentication (opens in a new tab)
- RFC 4231: Identifiers and Test Vectors for HMAC-SHA-224, HMAC-SHA-256, HMAC-SHA-384 and HMAC-SHA-512 (opens in a new tab)
- RFC 8032: Edwards-Curve Digital Signature Algorithm (EdDSA), section 7.1 test vectors (opens in a new tab)
- NIST CAVP: FIPS 186-3 RSA test vectors archive (SigGen15_186-3.txt) (opens in a new tab)
- MDN Web Docs: SubtleCrypto.sign() (last modified 27 April 2025) (opens in a new tab)
- Capital Markets Law No. 6362, consolidated text, Article 99/A (Turkish) (opens in a new tab)
- SPK (Capital Markets Board): Announcement on crypto-asset service providers, 5 August 2024 (Turkish) (opens in a new tab)
This guide is general information about software and markets, not investment, legal or tax advice. Automated trading can lose money, past or backtested performance does not guarantee future results, and the rules that apply depend on your jurisdiction and your exchange's terms. Sources, checks and corrections: see the editorial policy.