# API signature generation: HMAC, RSA and Ed25519 tested

URL: https://fincodelabs.com/en/blog/api-signature-generation · Publisher: Fincode (Fincode Yazılım ve Teknoloji A.Ş.), Istanbul, Turkey · Category: Exchange APIs · Published: 2026-11-26 · Updated: 2026-11-26

API signature generation: what six exchanges sign, HMAC vs digital signature, code tested on RFC, NIST and exchange vectors, and why valid secrets fail.

**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.

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.

**From each official page, 5 November 2026 (alphabetical, not a ranking)**

| 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](https://github.com/coinbase/coinbase-advanced-py) 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](https://fincodelabs.com/en/blog/bybit-api-python), [Coinbase](https://fincodelabs.com/en/blog/coinbase-advanced-trade-api-python), [OKX](https://fincodelabs.com/en/blog/okx-api-python) and [Kraken](https://fincodelabs.com/en/blog/kraken-api-python) guides, with BtcTurk in [Turkish crypto exchange APIs](https://fincodelabs.com/en/blog/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.

```python
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&timestamp=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 bytes
```

Each 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&...&timestamp=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.

```python
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&timestamp=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
```

**Failure causes: tested results from the script above, or the platform's own page**

| 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 |

**How each platform reports it, from its error pages, 5 November 2026**

| Platform | Bad signature | Time or nonce |
| --- | --- | --- |
| Binance | `-1022` | `-1021` |
| BtcTurk | 401 Invalid Signature | 401 Invalid Nonce |
| [Bybit](https://bybit-exchange.github.io/docs/v5/error) | `10004` | `10002` |
| Kraken | `EAPI:Invalid signature` | `EAPI:Invalid nonce` |
| OKX | `50113` | `50102` |

Details for Binance are in [Binance API error codes](https://fincodelabs.com/en/blog/binance-api-error-codes). Do not retry in a loop: [Kraken's error page](https://docs.kraken.com/exchange/guides/general/errors) 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.

**Sizes and repeatability measured on 5 November 2026 with the vectors above and throwaway keys**

| 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.md` and the [developer site](https://developers.binance.com/en/docs/products/spot/rest-api) (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 -sign` printed "Key type not supported for this operation", while `openssl pkeyutl -sign -rawin` returned 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](https://fincodelabs.com/en/blog/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.

1. Reproduce a published answer offline with the script above.
2. Log the exact string you signed, never the secret, and compare it with the bytes on the wire.
3. Only then try a testnet or demo key against the matching host.

For integration work in general, see Fincode's [exchange API integration](https://fincodelabs.com/en/services/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](https://fincodelabs.com/en/tools/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)](https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md)
- [Binance Spot API documentation: API key types (HMAC deprecated, sample keys)](https://github.com/binance/binance-spot-api-docs/blob/master/faqs/api_key_types.md)
- [BtcTurk API documentation: Authentication V1](https://docs.btcturk.com/docs/authentication/authentication-v1)
- [BtcTurk API documentation: FAQ (401 Invalid Signature)](https://docs.btcturk.com/docs/faq-frequently-asked-questions)
- [Bybit V5 API: Integration guidance (signature rule, recv_window)](https://bybit-exchange.github.io/docs/v5/guide)
- [Coinbase Developer Documentation: API key authentication (JWT, ES256)](https://docs.cdp.coinbase.com/coinbase-app/authentication-authorization/api-key-authentication)
- [Kraken: Spot REST authentication (API-Sign example)](https://docs.kraken.com/exchange/guides/rest/authentication)
- [OKX API v5 documentation: REST authentication, WebSocket login, error codes](https://www.okx.com/docs-v5/en/)
- [RFC 2104: HMAC: Keyed-Hashing for Message Authentication](https://www.rfc-editor.org/rfc/rfc2104.html)
- [RFC 4231: Identifiers and Test Vectors for HMAC-SHA-224, HMAC-SHA-256, HMAC-SHA-384 and HMAC-SHA-512](https://www.rfc-editor.org/rfc/rfc4231.html)
- [RFC 8032: Edwards-Curve Digital Signature Algorithm (EdDSA), section 7.1 test vectors](https://www.rfc-editor.org/rfc/rfc8032.html)
- [NIST CAVP: FIPS 186-3 RSA test vectors archive (SigGen15_186-3.txt)](https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/dss/186-3rsatestvectors.zip)
- [MDN Web Docs: SubtleCrypto.sign() (last modified 27 April 2025)](https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/sign)
- [Capital Markets Law No. 6362, consolidated text, Article 99/A (Turkish)](https://www.mevzuat.gov.tr/mevzuatmetin/1.5.6362.pdf)
- [SPK (Capital Markets Board): Announcement on crypto-asset service providers, 5 August 2024 (Turkish)](https://spk.gov.tr/duyurular/basin-duyurulari/2024/kripto-varlik-hizmet-saglayicilara-iliskin-duyuru_05082024)

> 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](https://fincodelabs.com/en/editorial-policy).

---

Published by Fincode (Fincode Yazılım ve Teknoloji A.Ş.), a software company in Istanbul, Turkey: https://fincodelabs.com/en/blog/api-signature-generation

Cite as: Fincode, "API signature generation: HMAC, RSA and Ed25519 tested", updated November 26, 2026, https://fincodelabs.com/en/blog/api-signature-generation
