HMAC Generator - HMAC-SHA256, SHA1, SHA512 Online
—What This HMAC Generator Does
HMAC (hash-based message authentication code, RFC 2104) combines a secret key with a hash function to produce a tag for a message. If the message or the key changes by a single bit, the tag changes completely. This tool calculates HMAC-SHA1, HMAC-SHA256, HMAC-SHA384 and HMAC-SHA512 and shows the result as hex or Base64, which are the two formats APIs normally expect.
How to Generate an HMAC
- Paste the exact message into the Message box. Spaces and line breaks count.
- Enter the secret key and choose whether it is text or hex.
- Pick the algorithm and the output format.
- Copy the result. It updates as you type.
Worked Example
RFC 4231 includes a test case you can use to check any HMAC
implementation. With the key Jefe (as text) and the message
what do ya want for nothing?, HMAC-SHA256 in hex is:
5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843
Switch the output to Base64 and the same 32 bytes are shown as
W9zBRr9gdU5qBCQmCJV1x1oAPwidJzmDnexYuWTsOEM=. Both strings
hold identical data, so make sure you compare like with like.
How HMAC Works
HMAC runs the hash function twice. First the key is padded to the hash's
block size (64 bytes for SHA-1 and SHA-256, 128 bytes for SHA-384 and
SHA-512) and XORed with a repeated 0x36 byte. That is
prepended to the message and hashed. The key is then XORed with
0x5c, prepended to the first hash, and hashed again. Keys
longer than the block size are hashed first. This two-step design is
what protects HMAC from length-extension attacks that affect a naive
hash(key + message), and it is why HMAC-SHA1 remains safe
even though plain SHA-1 has known collisions.
Common Uses for HMAC
- Webhook signatures. The sender signs each request
with a shared secret and your server recomputes the HMAC to check it.
The details differ: GitHub sends
X-Hub-Signature-256: sha256=<hex>over the raw body, Shopify sends Base64 inX-Shopify-Hmac-Sha256, and Stripe signs the timestamp, a dot and the body, then sends the hex result asv1=inStripe-Signature. Always hash the raw bytes you received, not JSON you have parsed and re-serialised. - API request signing. Some APIs ask clients to sign a canonical string made of the method, path, timestamp and body.
- JWT HS256. The signature of an HS256 token is the
HMAC-SHA256 of
header.payload, Base64URL-encoded. You can check one with the JWT decoder. - Signed cookies and links. An HMAC on a cookie value or expiring download link stops users from editing it.
Security Notes
An HMAC is only as strong as its key. Use a long random key (32 bytes or more for SHA-256) rather than a word or phrase. When you check a tag in code, use a constant-time comparison function so attackers cannot learn the correct value from response timing. An HMAC proves integrity and origin, but it does not hide the message; encrypt the data as well if it is secret. To hash data without a key, use the hash generator.
Related Tools
JWT Decoder
Decode JSON Web Tokens and inspect header, payload and signature.
Base64 Encode / Decode
Encode text to Base64 or decode Base64 strings back to plain text.
URL Encode / Decode
Percent-encode or decode URLs and query-string parameters safely.
Hash Generator
Generate MD5, SHA-1, SHA-256, SHA-384, and SHA-512 hashes from text.