HMAC Generator

Computes an HMAC — a hash keyed with a shared secret — using SHA-1, SHA-256, SHA-384 or SHA-512, with hex or Base64 output. This is what webhook signatures, API request signing and signed cookies are built from, and what you need when you are debugging why a signature does not match.

Live demo · real result from this tool
Output

HMAC-SHA-256

5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843

Processed on your device — nothing is uploaded.

How to use HMAC Generator

  1. Pick the algorithm the other system uses — SHA-256 unless its documentation says otherwise.
  2. Enter the shared secret key exactly, with no added whitespace.
  3. Paste the exact message being signed — the raw body, not a reformatted copy.
  4. Choose hex or Base64 to match the format you are comparing against, then copy the result.
  5. Computed with the Web Crypto API, the browser’s own cryptographic implementation.
  6. Hex output is lowercase; some providers publish uppercase, so compare case-insensitively.
  7. The key and message stay in your browser — but treat any secret pasted into any web page as worth rotating afterwards if it is a production key.

What HMAC adds that a plain hash does not

A hash proves a message has not changed. It does not prove who sent it, because anyone can hash anything. HMAC mixes a secret key into the hash in a specific two-pass construction, so only someone holding the key can produce a valid digest for a message — and anyone holding the key can verify one. That is why every webhook provider signs its payloads this way: the signature in the header proves the request came from them and arrived intact.

Why the construction matters, not just the ingredients

The obvious approach — hashing the key followed by the message — is broken for the SHA-1 and SHA-2 families, because their internal structure lets an attacker append data to a message and compute a valid digest for the longer version without knowing the key. That is the length-extension attack. HMAC’s two nested hashes with padded key variants close it. The practical lesson is to use HMAC rather than inventing a scheme, even a plausible one.

Debugging a signature mismatch

When a webhook signature will not verify, it is almost never the algorithm. In order of likelihood: you are hashing the parsed and re-serialised body instead of the exact raw bytes received; the output encoding differs (hex against Base64, or uppercase against lowercase hex); the key has trailing whitespace from a copy-paste or a .env file; or the provider signs a constructed string — timestamp plus a dot plus body — rather than the body alone. Reproduce it here with a known payload before you change any code.

Choosing the algorithm, and comparing safely

SHA-256 is the default nearly everywhere and the right choice for new work. HMAC-SHA1 is still in wide use and, unusually, is not considered broken — HMAC’s security does not rest on the collision resistance that SHA-1 lost — but there is no reason to choose it now. Whichever you use, compare signatures with a constant-time comparison in production code: a normal string comparison returns early on the first differing byte, which leaks enough timing information to forge a signature byte by byte.

Frequently asked questions

What is an HMAC?
A keyed hash that proves both the integrity and authenticity of a message — only someone with the secret key can produce a matching code.
How is HMAC different from a plain hash?
A plain hash uses no key, so anyone can recompute it. HMAC mixes in a secret key so the code cannot be forged without it.
Which algorithm should I choose?
SHA-256 is a strong default; use SHA-384 or SHA-512 for extra margin. Avoid SHA-1 for new security-sensitive uses.
What is the difference between HMAC and a plain hash?
A plain hash takes only the message, so anyone can compute it and it proves only integrity. HMAC takes a message and a secret key, so a valid digest proves both integrity and that the sender knows the key — authentication as well as integrity.
Is HMAC-SHA1 still safe?
For HMAC specifically, yes — the attacks that broke SHA-1 target collision resistance, which HMAC's security does not depend on, and HMAC-SHA1 remains unbroken and is still used in TOTP and older AWS signatures. Use SHA-256 for anything new all the same; there is no cost to it.
My webhook signature will not verify. What should I check first?
The raw body. Most frameworks parse JSON before your handler sees it, and re-serialising changes whitespace and key order, which changes the digest. Capture the unmodified bytes, then check the encoding (hex or Base64), then check the key for stray whitespace, then check whether the provider signs a timestamp-prefixed string rather than the body alone.

Written by the ToolsRift team · Last updated

Pages are drafted with AI assistance and checked by automated tests. How we write and check pages.

Was this tool useful?

Report a problem

Start typing to search every tool.

↑ ↓ to moveEnter to openEsc to close