Browser processing Input is processed on your device. Privacy & storage

HMAC Generator

Keyed hashing with SHA-1, SHA-256, SHA-384 or SHA-512 — computed locally, plus the one-liner to reproduce it in your own code.

Message 0 characters
Secret key
HMAC —
Reproduce it in code
 

Why a key changes everything

A plain hash proves only that the data has not changed — anyone can recompute it, so anyone who can edit the data can also fix the hash. HMAC folds a secret key into the compression function, so producing a valid tag requires the key. That is what turns a checksum into an authentication code: it answers “did this come from someone who holds the key, and is it intact?”

Structurally HMAC is H(key ⊕ opad ‖ H(key ⊕ ipad ‖ message)). The two nested hashes and the padding constants exist so that the construction stays secure even when the underlying hash has weaknesses that would break a naive H(key ‖ message) — the length-extension problem. In practice you never implement it by hand; every platform ships it.

Where you will meet it

  • JWT with HS256 — the signature is an HMAC over base64url(header) + "." + base64url(payload) with the shared secret as the key.
  • Webhook verification — Stripe, GitHub, Slack and friends sign the raw request body and send the result in a header.
  • AWS Signature Version 4 — a chain of HMACs that derives a signing key from your secret access key.
  • Cookie and form signing — frameworks sign a value so a client cannot tamper with it unnoticed.
  • PBKDF2, HKDF, TOTP — all built on HMAC as the primitive.

Comparing a tag safely

Compare the computed tag against the received one with a constant-time function, not ==. A byte-by-byte comparison that returns early leaks how many leading bytes matched, which is enough to recover a valid tag one byte at a time. Use crypto.timingSafeEqual() in Node, hmac.compare_digest() in Python, or hash_equals() in PHP.

FAQ

HMAC-SHA1 or HMAC-SHA256?

SHA-256 unless something forces SHA-1. HMAC-SHA1 is still considered sound for keyed authentication — the collision attacks on SHA-1 do not translate into HMAC forgeries — but it is a bad look in an audit and provides no benefit. Pick SHA-256.

Can I use HMAC to store passwords?

No. HMAC is fast, and fast is the enemy for passwords. Use a deliberately slow, memory-hard KDF — Argon2id, scrypt or bcrypt. HMAC is for message authentication, not password storage.

Is my key uploaded?

No. Key import and signing both happen through the browser's Web Crypto API in this page. There is no network request — open the Network tab and check.

Why is the output length fixed?

Because HMAC always produces the full digest of the hash — 32 bytes for SHA-256, 64 for SHA-512. If a protocol needs a shorter tag it truncates, and that is part of the protocol spec, not a free choice.