How to use the HMAC Generator
- 1
Paste the message
Enter the exact text that was signed — for a webhook, the raw request body byte for byte.
- 2
Enter the secret and its format
Choose Text (UTF-8), Hex or Base64 to match how your provider gives you the key.
- 3
Pick the algorithm
HMAC-SHA256 is the usual choice; SHA-384, SHA-512 and SHA-1 are also available.
- 4
Compare
Copy the hex or Base64 signature, or paste the one you received into the verify box for an instant match / no-match.
Features
Web Crypto HMAC
Signatures come from the browser’s built-in crypto.subtle implementation.
Flexible keys
Hex keys may include spaces or a 0x prefix; Base64 keys may use the URL-safe alphabet.
Two encodings
Lowercase hex and standard Base64 are shown side by side.
Smart verify
Accepts hex, Base64 or Base64URL, with or without padding, and strips prefixes like sha256= or v1=.
Size shown
The status reports the signature size: 160, 256, 384 or 512 bits.
Nothing uploaded
Message and key stay in the page and are not saved.
Who uses it — and for what
Webhook debugging
Find out why a payment or Git webhook fails its signature check.
API signing
Reproduce request signatures while building a client.
Writing tests
Produce expected signatures for unit tests.
Learning cryptography
See how one changed character changes the whole MAC.
What is HMAC?
HMAC (hash-based message authentication code) combines a message with a secret key using a hash function such as SHA-256. Anyone with the key can compute the same signature, but without the key it’s infeasible to forge one, so HMAC proves a message came from someone who knows the secret and wasn’t altered. It’s used to sign webhooks (Stripe, GitHub, Shopify, Slack), API requests (AWS Signature v4), JWTs with HS256 and session cookies.
Verifying a webhook
Take the raw request body exactly as received (before parsing or re-formatting JSON — a single space changes the signature), your webhook secret and the algorithm the provider uses, then compare with the signature header. GitHub sends sha256=<hex>; Shopify sends Base64; Stripe signs timestamp.body. In production, compare signatures with a constant-time function. HMAC is computed with your browser’s Web Crypto API — secrets never leave your device.
How HMAC works under the hood
HMAC is defined in RFC 2104. Instead of simply hashing key + message — which is vulnerable to length-extension attacks with SHA-256 — it hashes twice with two derived keys:
HMAC(K, m) = H( (K' XOR opad) || H( (K' XOR ipad) || m ) )K′ is the key padded to the hash’s block size (64 bytes for SHA-1 and SHA-256, 128 bytes for SHA-384 and SHA-512), or hashed first if it is longer than a block. ipad and opad are fixed byte patterns (0x36 and 0x5c repeated). The result is the same length as the hash: 20 bytes for SHA-1, 32 for SHA-256, 48 for SHA-384 and 64 for SHA-512.
Key length matters. A key shorter than the hash output weakens the MAC, so providers usually issue random secrets of 32 bytes or more. Keys longer than a block are allowed but are hashed down, so they add nothing beyond that point.
Matching common webhook schemes
Each provider signs slightly differently. Read its documentation for the exact string, but these patterns cover most cases:
| Pattern | What to paste as the message | Output to compare |
|---|---|---|
Header like X-Hub-Signature-256: sha256=… | The raw body | Hex (the prefix is stripped in the verify box) |
| Header with a Base64 value | The raw body | Base64 |
Header like t=1795861800,v1=… | The timestamp, a dot, then the raw body: 1795861800.{…} | Hex of the v1 value |
| Signed request strings (cloud APIs) | The canonical string the provider defines | Usually hex, often with a derived key |
Timestamped schemes exist to stop replay attacks: your server should also reject messages whose timestamp is more than a few minutes old. Paste only the signature value into the verify box — for a header that contains several fields, copy the part after v1=.
Verifying correctly in your own code
- Read the raw bytes. Frameworks often parse JSON before your handler runs. In Express use
express.raw()on the webhook route; in other frameworks find the “raw body” option. - Compare in constant time. Use
crypto.timingSafeEqual(Node),hmac.compare_digest(Python) orhash_equals(PHP) so attackers cannot learn the signature one byte at a time from response timing. - Watch character encodings. HMAC works on bytes. This tool encodes the message as UTF-8; if a system signs Latin-1 or UTF-16 text, results differ for non-ASCII characters.
- Keep the secret secret. Use a test or sandbox webhook secret in tools like this one. Even though nothing is sent from this page, a production signing secret should not be pasted into any website, chat or ticket; if it leaks, rotate it in the provider’s dashboard.
Worked examples
The default example
Message {"event":"payment.succeeded","id":"evt_123"}, key my-secret-key (text), HMAC-SHA256 gives:
- Hex:
36181b838916ca1c5c5aa22d17fa041cb8d3e0e808636ca241a5f4331b06a4cb - Base64:
Nhgbg4kWyhxcWqItF/oEHLjT4OgIY2yiQaX0MxsGpMs=
Both are the same 32 bytes written two ways. Pasting sha256=36181b83…a4cb into the verify box shows “Signature matches”.
One space changes everything
Re-format the same JSON as {"event": "payment.succeeded", "id": "evt_123"} (spaces after the colons and comma) and the SHA-256 signature becomes ad01ead5d601643f…7b4e1a — nothing in common with the original. This is why you must verify the raw body, never JSON.stringify(JSON.parse(body)).
Same key in hex
The text key my-secret-key is the bytes 6d792d7365637265742d6b6579. Choose Hex as the key format, paste those bytes, and the signature is identical: 36181b83…a4cb. Mixing up key formats is the second most common reason signatures do not match.
Checking against a published test vector
RFC 4231 test case 2 uses the key Jefe and the message what do ya want for nothing?. HMAC-SHA256 here returns 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843, which matches the value published in the RFC.
Pro tips
- Trailing newlines count. If your body ends with \n, make sure the message box does too.
- If hex matches but your code says no, check you are comparing lowercase hex to lowercase hex.
- For plain hashes without a key, use the hash generator instead.
Glossary
- MAC
- Message authentication code: a short tag proving a message came from a key holder and was not changed.
- Raw body
- The exact bytes of an HTTP request body before any parsing.
- Constant-time comparison
- Comparing two values in a way that always takes the same time, to avoid leaking information.
- Replay attack
- Re-sending a captured valid message; timestamps and nonces prevent it.
Frequently asked questions
Is HMAC the same as hashing?
No — a plain hash needs no key; HMAC requires a secret key, so it authenticates the sender.
Why doesn’t my webhook signature match?
Usually the body was re-serialised or trimmed, or the wrong secret/encoding was used.
Is HMAC-SHA1 still safe?
HMAC-SHA1 is still considered secure, but prefer SHA-256 for new systems.
Why are the hex and Base64 outputs different lengths?
They encode the same bytes differently: hex uses 2 characters per byte, Base64 about 1.33, so a 32-byte SHA-256 MAC is 64 hex or 44 Base64 characters.
Does the verify box accept uppercase hex?
Yes. Hex input is compared case-insensitively; Base64 is compared exactly, with or without = padding.
Can I use an empty key?
No. The tool asks for a secret key, because an HMAC without one gives no authentication.
Last updated 2026-11-28 · Built by Vinayak Agarwal · Part of Developer & Web (77 tools)