99tools

HMAC Generator

runs in your browser

Sign a message with a secret key using HMAC-SHA1, SHA256, SHA384 or SHA512, in hex or Base64, and check it against a signature you were given.

Message

Secret key

Key is

If the API gave you the key as hex or Base64, say so here. Signing a hex key as text produces a wrong signature with nothing to tell you.

Check against a signature you were given

about this tool

What HMAC is for

A plain hash tells you whether a message changed. An HMAC tells you whether it came from someone holding the secret. That is the difference that matters when you are verifying a webhook: an attacker can compute the hash of anything, but cannot produce a valid signature without the key.

HMAC also exists because the obvious approach does not work. Hashing the key followed by the message is vulnerable to a length-extension attack against older hash functions, where someone who knows the digest can append to the message and produce a valid digest for the longer version without ever seeing the key. HMAC's two-pass construction closes that.

The key encoding is the usual mistake

Secrets are handed out as plain text, hex or Base64, and the three produce completely different signatures from the same characters. A 64-character hex secret read as text is 64 bytes; read as hex it is 32. Both sign happily and only one matches.

If your signature is wrong and you are certain the message is right, this is almost always why. The setting is next to the key for that reason.

When it does not match

Two things account for nearly every mismatch. The first is the key encoding above. The second is that the message is not byte for byte what was signed: a trailing newline, the raw request body versus a re-serialised copy of it, or different line endings. Sign the exact bytes you received, before any parsing.

SHA-1 here is not the broken SHA-1

SHA-1 on its own is broken for signatures, because collisions can be manufactured. HMAC-SHA1 is a different construction and remains sound, which is why plenty of established APIs still use it. Prefer SHA-256 for anything new, but there is no need to panic about an existing integration.

Nothing leaves your browser

The message and the key are used in the page and never sent anywhere. That said, a production secret pasted into any web page is a secret that has been in a clipboard and a browser process. For a real key, prefer a local tool.