HMAC Generator

Algorithm—
Hex length—
Message characters—

How HMAC Generator is calculated: HMAC = Hash((key XOR opad) || Hash((key XOR ipad) || message)). A key longer than the block is hashed first; a shorter key is padded with zeros.

What is an HMAC generator?

An HMAC generator computes a keyed hash of a message — a short fingerprint that only someone with the secret key could have produced. Give it the message "The quick brown fox jumps over the lazy dog" and the key "key", and HMAC-SHA256 returns the 64-character hex string starting f7bc83f4. Change one letter of the message or the key, and the whole output changes.

HMAC is how APIs prove a request is genuine. A webhook sender signs the payload with a shared secret, and the receiver recomputes the HMAC with the same secret — if the two match, the payload is authentic and unmodified. It is also how signed URLs, session tokens, and message authentication work across the web.

This tool computes HMAC-SHA256 and HMAC-SHA512 entirely in your browser, with a hand-written implementation of both hash functions — no library, no server, and no data leaving your device. The output is deterministic: the same message and key always give the same HMAC.

How HMAC works

HMAC mixes the key into the hash twice. First the key is padded to the hash's block size — 64 bytes for SHA-256, 128 bytes for SHA-512 — with zeros, or hashed first if it is longer than the block. Then the padded key is XORed with a repeating 0x36 byte to make the inner pad, and with 0x5c to make the outer pad.

The inner hash runs over the inner pad followed by the message. The outer hash runs over the outer pad followed by the inner hash. The result is the HMAC. The two pads matter: without them, a plain hash of key-plus-message would be vulnerable to length-extension attacks, where an attacker extends a signed message without knowing the key.

The output is hexadecimal: HMAC-SHA256 produces 32 bytes, written as 64 hex characters, and HMAC-SHA512 produces 64 bytes, written as 128 hex characters. The length shown above the output tells you which algorithm ran — 64 means SHA-256, 128 means SHA-512.

The key, explained

The key is the secret, and its strength is the security. A key of "key" is fine for learning and for test vectors, but a real key should be long and random — at least 32 random bytes, generated once and stored securely. Anyone with the key can sign any message, so a leaked key means forged signatures.

A key longer than the block is hashed first: a 90-byte key for HMAC-SHA256 is hashed down to 32 bytes before use. That is by design, and the tool follows it exactly — the test vectors for long keys match the standard, which was verified against Python's hmac module.

An empty key is allowed by the tool but means nothing is secret: the HMAC of a message with an empty key can be computed by anyone. If the key field is empty, treat the output as a plain hash, not as a signature. Never paste a real production key into any web page you do not trust — this page runs locally in your browser, but the habit matters.

The key is the only secret in HMAC, and its length matters more than its content. A key shorter than the hash output — shorter than 32 bytes for SHA-256 — is padded with zeros to the block size, which is fine, but a short key is easier to guess, and a guessed key forges signatures. A key of 32 random bytes or more is the usual recommendation, and the key should be stored as a secret, never committed to a repository or pasted into a chat. The generator lets you type any key, but a key you made up from a word is weaker than a key from a random generator.

A worked example: signing a message

Take the default message, "The quick brown fox jumps over the lazy dog" — 43 characters — and the key "key". HMAC-SHA256 gives a 64-character hex string starting f7bc83f4 and ending 1a3cd8. That value is a published test vector: it is the answer every correct HMAC-SHA256 implementation gives for this message and key.

Change the key to "secret" and the output changes completely, even though the message is the same. Change one letter of the message and it changes completely again. That avalanche is what makes HMAC useful: a tampered message never produces the original signature, so any change is detected at once.

Switch the algorithm to HMAC-SHA512 and the same message and key give a 128-character hex string starting b42af090. The two algorithms are independent — a signature made with one cannot be checked with the other, so the sender and the receiver must agree on the algorithm as well as the key.

Who uses an HMAC generator, and why

API developers are the main users. A webhook receiver verifies the signature header by recomputing the HMAC of the payload with the shared secret, and a mismatch means the payload was tampered with or the secret is wrong. This tool is where the expected signature is computed during development.

Backend engineers are the second group. Signed URLs, password reset links, and session tokens all use HMAC to prove they were issued by the server and not forged. A generator is the fastest way to check a token by hand when debugging. A JWT generator builds signed tokens, which use HMAC to prove they were issued by the server.

Security engineers are a third group. HMAC is the building block of many protocols, and a generator with known test vectors is how an implementation is checked. A hash generator computes the plain hashes — MD5, SHA-1, SHA-256, SHA-512 — that HMAC is built on.

Webhook developers are a third group. A service that sends events to your server signs each one with HMAC, and your server must verify the signature before acting on the event, because anyone can send a fake event to the same URL. The generator is the tool for debugging that handshake: paste the payload and the shared secret, and the digest it produces is the signature the service should have sent. If they differ, the secret is wrong or the payload was changed, and the event must not be trusted.

HMAC vs plain hash

A plain hash proves nothing about who made it. Anyone can compute the SHA-256 of a message, so a SHA-256 value next to a message only proves the message was not changed after the hash was computed — it does not prove who computed it. HMAC adds the key, so only someone with the secret could have produced the value.

That is why webhooks sign with HMAC and not with a plain hash. The hash generator on this site gives you the plain hashes for checksums and fingerprints, while this tool gives you the keyed hash for authentication. Use a plain hash to check integrity, and HMAC to check authenticity.

Both tools share the same hash implementations, so they agree: the SHA-256 of a message from the hash generator is the same value this tool uses inside its HMAC. The difference is only the key — and the key is the whole point.

Common HMAC mistakes

The first mistake is a weak key. A key of "secret" or "password" can be guessed, and a guessed key forges signatures. Generate a long random key, store it as a secret, and never commit it to a repository or paste it into a chat. Generate one with a password generator, which produces random strings of any length.

Second: comparing signatures with == in code. A plain string comparison can leak timing information, which lets an attacker guess the signature one character at a time. Use a constant-time comparison — most languages provide one — when you check a signature in code.

Third: signing the wrong thing. A webhook signature covers the exact bytes of the payload, including whitespace. If your code re-serialises the JSON before checking, the bytes differ and the signature fails even though the data is the same. Sign and verify the raw bytes, not a re-formatted copy.

Fourth: using HMAC-SHA256 where the other side expects HMAC-SHA512, or the reverse. The algorithms produce different lengths — 64 hex characters against 128 — so a length mismatch is the first clue. Agree on the algorithm with the other side, and check the length first when a verification fails.

A second mistake is comparing two HMAC values with a plain string comparison that stops at the first difference. That comparison leaks timing information: an attacker can measure how long the comparison took and learn how many characters matched, which narrows the search for the right signature. The safe comparison is a constant-time one, which takes the same time whether the values match or not, and every serious framework provides one. The generator shows the value; the code that checks it must compare it safely.

How to use this HMAC generator

Type your message into the first box — the default is 43 characters — and your secret key into the second. Pick HMAC-SHA256 or HMAC-SHA512. The hex output updates live in the box below, with the algorithm, the hex length, and the message length above it.

To copy the HMAC, use the Copy button next to the output box. To check a signature, compute the HMAC of the received message with your key and compare it with the signature you received — if they match exactly, the message is authentic.

Everything runs in your browser. No sign-up, no account, no data sent anywhere — your message and your key never leave your device. It works offline once the page has loaded. Never paste a real production key into a page you do not trust, and never share a key in a chat or a ticket.

Type the message and the key, pick SHA-256 or SHA-512, and press generate. The output shows the hex digest and the base64 form, and either form is a valid signature — the choice depends on what the receiver expects, and the API documentation will say which. To check a signature, run the same message and key through the generator and compare the output with the signature you received; if they match, the message is authentic and unmodified.

Frequently Asked Questions

A plain hash such as SHA-256 proves a message was not changed after the hash was computed, but anyone can compute it. An HMAC mixes a secret key into the hash, so only someone with the key could have produced the value — which proves both integrity and authenticity.

64 hexadecimal characters, which is 32 bytes. HMAC-SHA512 is 128 hexadecimal characters, 64 bytes. The default message with the key key gives a 64-character HMAC-SHA256 starting f7bc83f4.

It is hashed first. For HMAC-SHA256 the block is 64 bytes, so a 90-byte key is hashed down to 32 bytes before use. A shorter key is padded with zeros. Both cases are part of the standard and are handled by this tool.

This page computes the HMAC entirely in your browser — the key never leaves your device. Even so, never paste a real production key into a web page you do not trust, and never share a key in a chat or a ticket. For learning and test vectors, a key such as key is fine.

More free tools

More calculators and utilities from Sortrun — free, no sign-up.