nrtechstudio.com tools / hmac-generator

Security tools · message authentication

HMAC Generator & Verifier

Compute HMAC-SHA256, HMAC-SHA512, HMAC-SHA1, and HMAC-MD5 tags from any message and secret key — then verify signatures exactly the way APIs, webhooks, and JWTs do. Free, no signup, no server.

✓ 100% client-side — keys never leave your browser ✓ RFC 4231 test vectors built in ⚠ For learning & legitimate verification — never share secret keys

HMAC Studio

engine: detecting…

0 bytes (UTF-8)

Test keys only — never paste a live production secret into any website.

20 bytes

HMAC output

Signature won't match? Check these first

1) Key encoding mismatch (text vs hex vs base64) — the #1 cause. 2) Invisible bytes: trailing newline, CRLF vs LF line endings, or Unicode normalization. 3) Wrong algorithm (SHA-256 vs SHA-512 tags are completely different). 4) Truncated or case-mangled hex during copy-paste. Case and whitespace in the signature field are normalized automatically.

Tip: press Ctrl+K to jump to the key field. Everything runs locally — try it offline.

Concepts

01What is HMAC?

HMAC (Hash-based Message Authentication Code, RFC 2104) is a way to prove both who sent a message and that it wasn't tampered with — using a shared secret key and a cryptographic hash function. The sender computes HMAC(key, message) and attaches the resulting tag; the receiver recomputes it with their copy of the key. Equal tags → the message is authentic.

This is different from a plain hash. Anyone can compute SHA256("transfer $100"), so a bare digest proves nothing about origin. HMAC binds the digest to a secret only the legitimate parties know:

PropertyPlain hash (SHA-256)HMAC-SHA256
Detects accidental corruptionYesYes
Proves who created itNo — anyone can hashYes — needs the secret key
Survives an active attackerNoYes
Typical useFile checksums, Git objectsAPI signatures, webhooks, JWT (HS256), TOTP

Not encryption, not a signature scheme

HMAC provides authentication, not confidentiality — the message stays readable. Need to hide data? Use real encryption like our AES Encryptor. Need publicly verifiable signatures without a shared secret? That's what digital signatures (RSA/ECDSA) are for — see the comparison below.

Security pitfall

02Why hash(secret + message) is broken

It looks reasonable: prepend your secret, hash it, and only key holders can reproduce the digest. But hash functions like MD5, SHA-1, and SHA-256 are built on the Merkle–Damgård construction, which is vulnerable to length-extension attacks:

  1. Attacker observes SHA256(secret ‖ "amount=100"). They don't know secret.
  2. Because of how Merkle–Damgård finalizes, that digest is the internal state of the hash after processing secret ‖ "amount=100" ‖ padding.
  3. The attacker resumes hashing from that state and appends "&amount=99999" — producing a valid digest for a message they forged, without ever learning the secret.

HMAC was designed specifically to kill this attack. Its nested construction — H(K ⊕ opad ‖ H(K ⊕ ipad ‖ message)) — means the outer hash never processes attacker-controlled data directly, so extension is impossible. Rule of thumb: never invent your own MAC from a raw hash; use HMAC. (SHA-3/Keccak is immune to length extension, but HMAC remains the standard, audited choice everywhere.)

Under the hood

03How HMAC works, step by step

Let H be the hash (e.g. SHA-256) with block size B (64 bytes for SHA-256):

HMAC(K, m) = H( (K' ⊕ opad) ‖ H( (K' ⊕ ipad) ‖ m ) )
K' = K padded with zeros to B bytes (hashed first if longer than B)
ipad = 0x36 repeated B times  ·  opad = 0x5c repeated B times
  1. Normalize the key. If the key is longer than the block size, hash it down; then pad with zeros to exactly one block (K').
  2. Inner hash. XOR the key block with ipad, append the message, and hash the whole thing. This binds the key to the message.
  3. Outer hash. XOR the key block with opad, append the inner digest, and hash again. The outer layer is what defeats length extension.
  4. Encode. Output the raw bytes as hex or base64 — both represent the same tag.

Try it: the generator above uses this exact construction (pure JavaScript fallback included), and its output is byte-identical to Python's hmac module and OpenSSL on the RFC 4231 test vectors.

Worked examples

04HMAC-SHA256, computed by hand (RFC 4231)

Three official test vectors from RFC 4231, walked through so you can follow every byte. Click Load into generator to reproduce each one live above.

Example 1 — short key, short message (Case 1)

Key (hex)
0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b (20 bytes)
Message
"Hi There"
Inner
SHA256((key ⊕ ipad) ‖ "Hi There")
Outer
SHA256((key ⊕ opad) ‖ inner-digest)
HMAC-SHA256
b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7

Example 2 — text key (Case 2)

Key (text)
"Jefe" = hex 4a656665
Message
"what do ya want for nothing?"
Note
Same bytes, different encodings, same tag — encoding is only representation.
HMAC-SHA256
5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843

Example 3 — binary key & binary message (Case 3)

Key (hex)
aa × 20 bytes
Message
dd × 50 bytes (not text — raw bytes)
Note
HMAC works on bytes, not characters — this is why UTF-8 vs Latin-1 mismatches break real-world signatures.
HMAC-SHA256
773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe

Reference

05Which HMAC variant should you use?

AlgorithmTag sizeVerdict
HMAC-SHA25664 hex charsDefault choice. Standard for APIs, webhooks (Stripe, GitHub, Slack), and JWT HS256.
HMAC-SHA512128 hex charsUse when a spec demands 512-bit strength. Slower on 32-bit CPUs, otherwise fine.
HMAC-SHA140 hex charsLegacy only. Still unbroken as a MAC, but SHA-1 is deprecated — verify old systems, don't build new ones on it.
HMAC-MD532 hex charsLegacy only. Same story as SHA-1, weaker hash. Included here for compatibility testing.

For anything new in 2026: HMAC-SHA256 with a 32-byte random key. That single sentence covers 99% of real-world needs.

In practice

06Where HMAC is used

API request signatures

The server issues you a secret. For each request you sign a canonical string — e.g. timestamp + method + path + body — and send the tag in a header (X-Signature). The server recomputes it; a match means the request is genuine and unmodified. Always include a timestamp and reject stale ones to stop replay attacks.

Webhook verification (Stripe, GitHub, Slack)

When a provider calls your URL, it signs the payload with a shared webhook secret. Paste the raw request body and your secret into the Verify tab above to check the signature manually — the same check your server should do on every delivery (using constant-time comparison).

JWT with HS256

An HS256 JSON Web Token signature is HMAC-SHA256 over base64url(header) + "." + base64url(payload). Everything you learn with this tool transfers directly to debugging JWT signatures.

One-time passwords (TOTP/HOTP)

The 6-digit codes from your authenticator app are truncated HMAC-SHA1 values (RFC 4226/6238). Our TOTP Generator shows the full pipeline.

Defensive guide

07Handling HMAC keys safely

⚠ A note on responsible use

This tool exists for learning and legitimate verification — debugging your own API signatures, studying RFC test vectors, validating webhook handlers. Never share secret keys, and never use HMAC tooling to forge signatures on systems you don't own or have explicit permission to test.

Comparisons

08HMAC vs the alternatives

HMAC vs digital signatures (RSA / ECDSA / Ed25519)

HMAC is symmetric: both sides share one secret, so either side can create tags — it can't prove which side signed (no non-repudiation). Digital signatures are asymmetric: a private key signs, anyone with the public key verifies. Use HMAC between parties that already share a secret (APIs, webhooks); use digital signatures for software updates, certificates, and anything the public must verify.

HMAC vs encryption (AES)

Different jobs: HMAC authenticates, encryption hides. A common secure pattern is encrypt-then-MAC: encrypt with AES, then HMAC the ciphertext. If you need the encryption half, see our AES Encryptor (tool #8).

HMAC vs classical ciphers

Caesar, Vigenère, and friends are historical toys — fun to study, trivially breakable, and absolutely not message authentication. If you're here from a cryptography course, our Cipher Lab (tool #315) covers classical ciphers interactively, with an explicit warning that they must never protect real data.

FAQ

09Frequently asked questions

What is an HMAC generator?

An HMAC generator computes a Hash-based Message Authentication Code: a fixed-length tag produced from a secret key plus a message using a hash function such as SHA-256. Anyone holding the same key can recompute the tag and confirm the message is authentic and unmodified. This tool generates HMAC tags with SHA-256, SHA-512, SHA-1, or MD5 entirely in your browser — no data ever leaves your device.

How do I generate an HMAC-SHA256 signature online?

Paste your message, enter your secret key (as text, hex, or base64), select SHA-256, and click Generate. The tool outputs the HMAC in hex and base64. For programmatic use, the equivalent one-liner in Python is hmac.new(key, message, hashlib.sha256).hexdigest(). Always compare signatures with a constant-time comparison to avoid timing attacks.

How do I verify an HMAC signature?

Switch to the Verify tab, enter the same key, message, and algorithm the sender used, then paste the signature you received. The tool recomputes the HMAC and reports MATCH or MISMATCH. A mismatch means the message was altered, the key is wrong, or the encoding (hex vs base64, uppercase vs lowercase) differs — check the troubleshooting tips below the verifier.

What is the difference between HMAC and SHA-256?

SHA-256 is a plain hash function: anyone can hash any message, so a bare SHA-256 digest proves nothing about who created it. HMAC combines SHA-256 with a secret key, so only key holders can produce or verify the tag. Use plain SHA-256 for integrity checks against accidental corruption (like file checksums); use HMAC when you need authentication — proof of origin.

Why is hash(secret + message) insecure?

Simply concatenating a secret with a message and hashing it is vulnerable to length-extension attacks on Merkle–Damgård hashes (MD5, SHA-1, SHA-256): an attacker who sees hash(secret ‖ message) can compute hash(secret ‖ message ‖ extra) without knowing the secret, forging valid tags for extended messages. HMAC's nested double-hash construction (with ipad and opad) was designed specifically to defeat this class of attack.

What is HMAC-SHA512 used for, and when should I choose it over SHA-256?

HMAC-SHA512 uses the SHA-512 hash function, producing a 128-character hex tag. Choose it when a protocol mandates 512-bit security (some government and banking standards do) or when you want extra margin against future cryptanalysis. For most API signatures and webhooks, HMAC-SHA256 is the standard choice and is faster on 32-bit systems.

Is HMAC-MD5 or HMAC-SHA1 still secure?

Surprisingly, yes — for message authentication specifically. The famous collision attacks on MD5 and SHA-1 break plain hashing, but HMAC's security does not rely on collision resistance in the same way, and no practical attack breaks HMAC-MD5 or HMAC-SHA1 as a MAC. Still, prefer HMAC-SHA256 for anything new: it removes all doubt and costs nothing extra. This tool includes MD5 and SHA-1 only for verifying legacy systems.

How long should my HMAC key be?

Use a random key at least as long as the hash output: 32 bytes (256 bits) for HMAC-SHA256, 64 bytes for HMAC-SHA512. Shorter keys still work but reduce the security margin; longer keys are hashed down internally and give no extra benefit beyond the output size. Never use a human-memorable password directly as a key — derive one with a KDF if you must start from a password.

Should my HMAC key be text, hex, or base64?

The encoding is just a representation — what matters is the exact bytes. The text 'Jefe' and the hex '4a656665' are the same key and produce the same tag; 'SmVmZQ==' in base64 is also identical. Mismatched signatures are most often caused by one side decoding the key as UTF-8 text while the other decodes it as hex. Use this tool's encoding selector to match whatever your API documentation specifies.

How do APIs use HMAC signatures?

The server gives you a secret key. For each request you build a canonical string (for example: timestamp + HTTP method + path + body), compute HMAC-SHA256 with your key, and send the tag in a header like X-Signature. The server recomputes it with its copy of the key; if the tags match, the request is authentic. Stripe, GitHub, Slack, and AWS webhooks all work this way. Include a timestamp and reject old ones to block replay attacks.

What is the difference between HMAC and a JWT signature (HS256)?

HS256 in a JWT is literally HMAC-SHA256: the signature is HMAC over the base64url-encoded header and payload, keyed with your secret. So everything on this page about generating and verifying HMAC-SHA256 applies directly to validating JWTs signed with HS256. (JWTs can also use RS256/ES256, which are asymmetric digital signatures — a different mechanism where verification needs only a public key.)

Is it safe to paste my secret key into this tool?

This tool runs 100% in your browser: the key is processed by JavaScript on your device and is never sent to any server (you can verify this by disconnecting from the network — the tool keeps working). Even so, treat production secrets with care: for learning and for verifying test vectors this tool is ideal, but never paste a live production key into any website if your security policy forbids it. Use the built-in random key generator for experiments.

Why doesn't my computed HMAC match the expected value?

The four usual suspects: (1) key encoding — text vs hex vs base64; (2) message encoding — an extra newline, different line endings (CRLF vs LF), or Unicode normalization; (3) wrong algorithm — SHA-256 vs SHA-512 produce completely different tags; (4) truncated or case-mangled hex when copy-pasting. The Verify tab normalizes case and whitespace for you — if it still mismatches, compare byte-by-byte with the sender.

HMAC vs digital signature: which should I use?

HMAC uses one shared secret: both sides can create and verify tags, so it cannot prove which side signed (no non-repudiation). A digital signature (RSA, ECDSA, Ed25519) uses a private key to sign and a public key to verify, so anyone can verify but only the key holder can sign — and signatures are non-repudiable. Use HMAC for API/webhook authentication between parties that already share a secret; use digital signatures for software distribution, certificates, and anything needing public verifiability.

Free tool by NRTechStudio