Hmac generator
Computes a hash-based message authentication code (HMAC) using a secret key and your favorite hashing function.
About Hmac generator
Computes an HMAC, a hash of a message mixed with a secret key, using MD5, SHA-1, SHA-2 (224, 256, 384, 512), SHA-3 or RIPEMD-160. An HMAC proves that a message was produced by someone who knows the key and was not altered on the way.
When you would use it
- Verifying webhook signatures from services that sign the request body with a shared secret.
- Reproducing the signature an API expects (request signing, signed URLs) to find out why yours is rejected.
- Checking an HMAC implementation against a known-good result.
How to use it
- Enter the message in the plain text field and the shared secret in the secret key field.
- Choose the hashing function; SHA256 is the usual one.
- Choose the output encoding (hex, base64, base64url or binary) and copy the HMAC.
Things worth knowing
- Both the message and the key are taken as UTF-8 text. If your key is binary or given as hex or base64, decode it first, because the tool will otherwise use the characters of that text as the key.
- A single extra space or newline in the message changes the whole result, so paste exactly the bytes that were signed, such as the raw request body, not a re-formatted version.
- Prefer SHA-256 or stronger. HMAC-MD5 and HMAC-SHA1 are still considered secure as MACs, but are kept mostly for older systems.
- Compare HMACs in constant time on your server (for example crypto.timingSafeEqual) rather than with ordinary string comparison.
Frequently asked questions
- What is the difference between HMAC and a plain hash?
- A plain hash can be computed by anyone, so it only detects accidental changes. An HMAC needs the secret key, so it also proves who produced the message and stops an attacker from forging a matching value.
- Why does my HMAC not match the one the service sent?
- Typical causes are a different output encoding (hex versus base64), a key that should have been decoded first, the wrong hash function, or a body that was changed by a framework before you signed it.