HMAC Generator
The HMAC Generator signs any message with HMAC-SHA-256, SHA-384, SHA-512 or SHA-1 in your browser, via Web Crypto — key as text, hex or Base64, outputs in hex, Base64 and Base64url side by side, byte counts for the key and the message, a random 256-bit key generator, a verify mode, and GitHub, Stripe and Slack webhook recipes. Test keys only — never paste a live production secret into any website.
How to Use
- 1
Type or paste the message to sign. For a webhook, that is the exact raw request body — not the parsed JSON re-serialised. A trailing newline changes the signature, so sign the exact bytes the server signed.
- 2
Enter the secret key and pick its encoding: text (UTF-8), hex, or Base64. Key encoding is the #1 reason signatures do not match — the same characters read as text vs hex are entirely different bytes. The byte counts next to both inputs let you rule out an encoding mismatch at a glance.
- 3
Pick the algorithm: HMAC-SHA-256 is the default and covers almost every real use. SHA-384 and SHA-512 are offered for services that require them; SHA-1 is legacy only. MD5 is not offered — it is broken for collision resistance and HMAC-SHA-256 replaces it everywhere.
- 4
Read the signature in three encodings side by side: hex, Base64, and Base64url. Copy the one the server expects — hex and Base64 are the same signature and will never match each other, so compare like for like.
- 5
To check a signature you received, paste it into Verify mode, pick its encoding, and click Verify — the page recomputes the signature from the message and key above and tells you whether they match. Verify mode is for debugging; real production verification belongs in your server code, with a constant-time comparison.
- 6
To debug a webhook, load a recipe: GitHub (X-Hub-Signature-256: sha256=<hex> over the raw body), Stripe (timestamp + '.' + raw body), or Slack (v0:timestamp:raw-body). Replace the placeholder secret and body with your own test values — the recipe only shows the shape.
Frequently Asked Questions
What is HMAC?
HMAC vs plain hash — what's the difference?
Which algorithm should I use?
Why doesn't my signature match the server's?
What is a webhook signature?
Is my key uploaded?
Can I use this to verify a production webhook?
Does HMAC prevent replay attacks?
What does a matching HMAC prove — and what doesn't it prove?
How is this different from the JWT Generator and the TOTP Generator?
Generative Answer & AI Documentation
What is the HMAC Generator?
The HMAC Generator is a raw-signature tool: message plus secret key in, HMAC signature out. HMAC (RFC 2104) takes a message and a secret key, pads the key, and hashes it with the message twice (inner and outer pad) to produce a signature only someone holding the key could have made. This page computes it with Web Crypto (crypto.subtle.importKey + crypto.subtle.sign) in your browser tab — nothing is uploaded, stored, or put in the URL, and there is no history section. The algorithm selector offers HMAC-SHA-256 (the default), SHA-384, SHA-512, and SHA-1 for legacy systems; MD5 is deliberately not offered, because it is broken for collision resistance and HMAC-SHA-256 replaces it everywhere. The key encoding selector (text/UTF-8, hex, Base64) matters more than it looks: the same characters read as text vs hex are entirely different bytes, and the byte counts next to both inputs let you rule out an encoding mismatch at a glance. The signature is shown in three encodings side by side — hex, Base64, Base64url — because servers expect different ones. Verify mode recomputes the signature from the message and key above and compares it with a pasted signature. The webhook recipes prefill the message and key in the format GitHub (X-Hub-Signature-256: sha256=<hex> over the raw body), Stripe (timestamp + '.' + raw body), and Slack (v0:timestamp:raw-body) sign. The page leads with its warning, not a footnote: test keys only, and HMAC alone does not prevent replay attacks.
Why use HMAC Generator offline?
Webhook signatures are the daily debugging job HMAC exists for: a delivery fails verification, and the question is always one of four things — the key encoding, the exact message bytes, the output format, or the algorithm. This page answers all four in one place: the byte counts show what was actually signed, the three output encodings sit side by side so you compare like for like, and the recipes show the exact shape each service signs. The second reason is the test vector. The RFC 4231 button loads a known-good case (key of twenty 0x0b bytes over "Hi There" → HMAC-SHA-256 b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7), so you can check the tool itself before you trust it with your debugging — if the tool reproduces the vector, the mismatch is in your inputs, not the implementation. The third reason is the no-storage stance: a page that signs with your keys must not keep them, and this one has no history, no saved keys, and no network calls — you can watch the Network tab and see zero requests. The fourth reason is scope honesty: this page signs raw messages and nothing else. It does not mint JWTs (the JWT Generator does that, using HMAC under the hood for HS256) and it does not make 2FA codes (the TOTP Generator does that, using HMAC under the hood for HOTP) — one owner per job, so the keyword and the tool stay the same shape.
When should you use this tool?
Use it when a webhook signature does not verify: load the GitHub, Stripe, or Slack recipe, replace the placeholder secret and body with your own test values, and compare the recomputed signature with the header you received. Use it when you are implementing request signing in your own API and need a known-good signature to test your server code against. Use it when you are learning how HMAC works: the RFC 4231 vector plus the byte counts make the construction visible — the same message with a different key encoding is a different signature, and the byte count is where that shows. Do not use it with a live production secret, ever — test keys only, and rotate any real secret that was pasted anywhere untrusted. Do not use it as production verification: verify mode here is for debugging, and real verification belongs in your server code with a constant-time comparison. Do not use it to prove a message is safe: a matching HMAC proves the sender held the key, not that the content is trustworthy.
Key Benefits
- Web Crypto signing (crypto.subtle) — no library, no upload, no server.
- Four algorithms: HMAC-SHA-256 (default), SHA-384, SHA-512, SHA-1 legacy — MD5 honestly omitted.
- Key encoding selector (text, hex, Base64) with byte counts for the key and the message — the #1 mismatch bug, visible at a glance.
- Hex, Base64, and Base64url outputs side by side, one click to copy each.
- Random 256-bit key generator (32 bytes, hex) for test secrets.
- Verify mode: paste a received signature and compare it with the recomputed one.
- GitHub, Stripe, and Slack webhook recipes with the exact signed-payload shape each service uses.
- RFC 4231 test vector one click away, so the implementation is checkable against the standard.
- No history, no storage, no network calls — the key exists only in this tab.
Common Use Cases
- Verifying a GitHub webhook signature: paste the raw body and the webhook secret, read the hex output, and compare it with X-Hub-Signature-256 after the sha256= prefix.
- Debugging 'my Stripe signature doesn't match': load the Stripe recipe and check, in order, the raw body (not parsed JSON), the key encoding, and the output format.
- Testing your own server's HMAC verification: generate a signature here with a test key and assert your server accepts it — and that a tampered body fails.
- Checking the tool against the standard: load the RFC 4231 vector and confirm the hex output is b0344c61…32cff7 before trusting any other result.
- Signing an API request the AWS Sig V4 / JWT HS256 way: the same construction — HMAC over a canonical string with a shared secret — with the timestamp and nonce included in the signed payload.
Developer Notes & Best Practices
Signing goes through Web Crypto: crypto.subtle.importKey('raw', keyBytes, { name: 'HMAC', hash }, false, ['sign']) followed by crypto.subtle.sign('HMAC', key, messageBytes), where the message is UTF-8 encoded with TextEncoder. Key decoding is hand-written in lib/hmacUtils.ts: hexToBytes (even length, 0–9a–f only), base64Decode (atob with a validity check), and plain UTF-8 text — no dependency. The three output encodings are the same bytes rendered three ways: bytesToHex, base64Encode (chunked btoa), and base64UrlEncode (+ → -, / → _, padding stripped). Verify mode decodes the pasted signature in its chosen encoding and compares it with the recomputed one in a length-independent loop that accumulates differences instead of returning on the first mismatch — a debugging aid, not a production guarantee: real verification belongs in server code with a constant-time comparison. The random key generator uses crypto.getRandomValues for 32 bytes, shown as hex. The RFC 4231 test vector is a constant in the same module, and the Node tests assert the Web Crypto implementation reproduces it digit-for-digit for SHA-256 (b0344c61…32cff7) and SHA-1 (b6173186…146be00), and agrees with Node's own crypto.createHmac for SHA-384 and SHA-512. Two honest limits are stated on the page: MD5 is not offered (HMAC-MD5 would need a hand-written pure-JS MD5, and MD5 is broken for collision resistance), and a browser comparison cannot make the constant-time guarantee production verification needs.
Which algorithm should you use?
| Algorithm | Digest | Use it when |
|---|---|---|
| HMAC-SHA-256 | 256-bit (64 hex chars) | Almost always — GitHub, Stripe, Slack, JWT HS256 |
| HMAC-SHA-384 | 384-bit (96 hex chars) | A service requires it |
| HMAC-SHA-512 | 512-bit (128 hex chars) | A service requires it |
| HMAC-SHA-1 | 160-bit (40 hex chars) | Legacy only — a system that cannot do SHA-256 |
| HMAC-MD5 | 128-bit | Never offered here — broken for collision resistance |
The webhook headers — what each service sends
| Service | Header | Signed payload | Signature format |
|---|---|---|---|
| GitHub | X-Hub-Signature-256 | Raw request body | sha256=<hex> |
| Stripe | Stripe-Signature | timestamp + '.' + raw body | t=<timestamp>,v1=<hex> |
| Slack | X-Slack-Signature | 'v0:' + timestamp + ':' + raw body | v0=<hex> |
Signature doesn't match? Check in this order
| # | Check | What goes wrong |
|---|---|---|
| 1 | Key encoding | Text vs hex vs Base64 are different bytes — the byte count shows what was used |
| 2 | Message bytes | A trailing newline, or re-serialised JSON instead of the raw body |
| 3 | Output format | Hex and Base64 never match each other — compare like for like |
| 4 | Algorithm | SHA-256 vs SHA-512 — the header or docs name it |
- Use HMAC-SHA-256 with a 32-byte random key unless a service requires otherwise — the Random 256-bit key button generates one.
- Sign the raw body, never re-serialised JSON: parsing and re-stringifying changes whitespace and key order, and the signature changes with it.
- Include a timestamp and a nonce in the signed payload and reject requests older than a few minutes — HMAC alone does not prevent replay.
- Compare like for like: hex against hex, Base64 against Base64 — the two encodings of the same signature never match each other.
- Check the RFC 4231 vector first when a signature does not match: if the tool reproduces b0344c61…32cff7, the mismatch is in your inputs.
- Rotate a key the moment you suspect it leaked — a compromised key means anyone holding it can forge valid signatures.
Common Mistakes
- Signing parsed-and-re-serialised JSON instead of the raw body — the signature changes with the whitespace.
- Reading the key as text when the server read it as hex (or the reverse) — the byte count next to the key input is where that shows.
- Comparing a hex signature with a Base64 one and concluding they differ — they are the same signature in different encodings.
- Pasting a live production secret into a website to test a webhook — use a test secret, and rotate any real secret that was ever pasted anywhere untrusted.
- Treating a matching HMAC as proof the message is safe — it proves key possession, not trustworthiness.
- Forgetting replay protection: a captured signed request replays verbatim, and the signature still checks out — sign a timestamp and a nonce, and reject old requests.
Limitations
This page signs raw messages in the browser and nothing else: it does not mint JWTs, make 2FA codes, or verify production webhooks — those jobs belong to the JWT Generator, the TOTP Generator, and your server code respectively. Verify mode is a debugging aid: the comparison loop is length-independent, but a browser check cannot make the constant-time guarantee production verification needs, so a timing leak is possible in principle. MD5 is not offered — HMAC-MD5 would need a hand-written pure-JS MD5, and MD5 is broken for collision resistance, so HMAC-SHA-256 replaces it everywhere. A matching HMAC proves the sender held the key and the message was not altered; it does not prove the message is safe, and it does not prevent replay — timestamps and nonces are still your job. Keys are test keys only: a live production secret must never be pasted into any website.
Structured Input/Output Example
Message: "Hi There" Key (hex): 0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b Algorithm: HMAC-SHA-256
Hex: b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7 Base64: sDRMYdjbOFPKqvzKD78SuIHcIAyTjpxLpN2ZxLDI/3c= Base64url: sDRMYdjbOFPKqvzKD78SuIHcIAyTjpxLpN2ZxLDI_3c — RFC 4231 test case 1, reproduced digit-for-digit.
Related Tools
Hash Generator
Hash generator: type any text and get its MD5, SHA-1, and SHA-256 digests side by side in real time. Compare algorithms at a glance. Free, offline.
SHA-256 Generator
SHA-256 generator: compute SHA-256 hashes — 256-bit digests as 64-character hex — from any text. The standard for download verification and signing.
JWT Generator
JWT generator: mint signed test tokens in your browser — HS256/384/512, RS256/384/512, PS256/384/512, ES256/384/512, editable claims, expiry countdown.
TOTP Generator
TOTP generator: live 2FA codes from a Base32 secret or otpauth:// URL — 6/8 digits, 30/60 s, SHA-1/256/512, prev/next codes, verify ±1, setup QR.
Unix Timestamp Converter
Unix timestamp converter: turn epoch seconds or milliseconds into local time, UTC, and relative times. Auto-detects seconds vs milliseconds.