ToolNimba

๐Ÿ” HMAC Generator (SHA-256, SHA-1, SHA-512)

Shihab Mia By Shihab Mia ยท Updated 2026-07-27

HMAC (hex)

Enter a message and key, then press Generate HMAC.

This HMAC generator turns a message and a secret key into a keyed hash that anyone holding the same key can reproduce and verify. Pick SHA-256, SHA-1, or SHA-512, paste your message and key, and read back the hex digest instantly. Everything runs locally in your browser using the built-in Web Crypto API, so your secret key and message never leave the page.

HMAC (Hash-based Message Authentication Code) is the workhorse behind webhook signatures, API request signing, and tamper checks. Use this tool to test a signing routine, reproduce a signature you received, or learn how the algorithm behaves when you change the key or the message by a single character.

What is the HMAC Generator?

HMAC is a way to prove two things at once: that a message has not been altered, and that it came from someone who knows a shared secret key. A plain hash like SHA-256 only protects against accidental change, because anyone can recompute it from the message alone. HMAC mixes a secret key into the hashing process, so only parties who hold the key can produce or check the value. The result is called a message authentication code, and it is what turns a hash function into an authentication primitive.

The algorithm is defined in RFC 2104 and standardized further in FIPS 198-1. It hashes the message together with two key-derived pads, an inner pad and an outer pad, in the pattern H(key XOR opad, H(key XOR ipad, message)). You do not have to do that by hand: the Web Crypto API does it for you. This tool calls importKey to load your secret as a raw HMAC key, then sign to produce the code, and finally converts the raw bytes to a hexadecimal string.

The output length depends on the chosen hash. HMAC-SHA1 returns 20 bytes (40 hex characters), HMAC-SHA256 returns 32 bytes (64 hex characters), and HMAC-SHA512 returns 64 bytes (128 hex characters). Because the result is deterministic, the same message and key always yield the same digest, which is exactly what lets a receiver verify it by computing the HMAC again and comparing the two strings.

A property that makes HMAC different from simply hashing the key and message together (like SHA256(key + message)) is resistance to length-extension attacks. Hash functions built on the Merkle-Damgard construction, including SHA-1, SHA-256, and SHA-512, let an attacker who knows H(secret + message) compute H(secret + message + extra) without ever learning the secret. The double-hashing structure of HMAC, with two independent pads, closes that gap, which is why RFC 2104 recommends HMAC instead of naive key-prefixing even when the underlying hash is otherwise trusted.

HMAC shows up across the stack: webhook providers sign event payloads with it, cloud APIs such as AWS Signature Version 4 build a canonical request and HMAC-SHA256 it in stages, and the HS256 and HS512 algorithms in a JWT are literally HMAC-SHA256 and HMAC-SHA512 applied to the header and payload with the JWT secret as the key. Understanding this tool means understanding a large slice of how modern web authentication actually works under the hood.

When to use it

  • Verifying incoming webhook payloads from providers such as Stripe, GitHub, or Slack that sign each request with HMAC.
  • Signing outgoing API requests where the server expects an HMAC of the request body or a canonical string, similar to AWS Signature Version 4.
  • Reproducing a signature you were given so you can confirm your own signing code, in Node.js, Python, or another language, matches the expected output.
  • Debugging a JWT that uses HS256 or HS512 by manually computing the HMAC of the header and payload against the shared secret.
  • Teaching or learning how a keyed hash differs from a plain hash by changing one character and watching the digest change completely.
  • Generating a short integrity tag for a configuration value, license key, or session token so tampering can be detected later.

How to use the HMAC Generator

  1. Type or paste the message you want to authenticate into the Message box.
  2. Enter the shared secret key in the Secret key field. It is treated as raw UTF-8 text.
  3. Choose the hash algorithm: SHA-256 is the common default, SHA-1 is legacy, and SHA-512 is the longest.
  4. Press Generate HMAC, or just edit any field and the digest updates automatically.
  5. Read the hexadecimal HMAC in the result box and press Copy to put it on your clipboard.
  6. To verify a signature you received, paste the same raw message and the same key, pick the matching algorithm, and compare the output character by character.

Formula & method

HMAC(K, m) = H((K′ XOR opad) ‖ H((K′ XOR ipad) ‖ m)), where H is the chosen hash (SHA-1, SHA-256, or SHA-512), K′ is the key padded or hashed to the block size, ipad is the byte 0x36 repeated, opad is the byte 0x5c repeated, and ‖ means concatenation.
MessageSecret keyHMAC functionSHA-256, SHA-1, or SHA-512Fixed-length hex digest (40 / 64 / 128 chars)

Worked examples

Compute the classic RFC test vector: HMAC-SHA256 of the message "The quick brown fox jumps over the lazy dog" with the key "key".

  1. Set the algorithm to SHA-256.
  2. Enter key as the secret key.
  3. Enter The quick brown fox jumps over the lazy dog as the message.
  4. The tool imports the key and signs the message with HMAC-SHA256.

Result: f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8 (64 hex characters).

See how a single character change in the key produces a completely different code for the same message.

  1. Keep the message "Hello, ToolNimba" and algorithm SHA-256.
  2. Use the key my-secret-key and note the digest.
  3. Change the key to my-secret-keys (one extra letter) and regenerate.
  4. Compare the two outputs character by character.

Result: With my-secret-key the digest is 07dd20208d9887eea59cabab647cbd560aa93750c21edcfbbc4dfcbcd5036402, and the changed key gives 7df6f8502875702b9713e0fc30b11b085be342ff054d47182a0f7cfbef20b002, an entirely different 64-character string despite only one extra letter in the key, which is the avalanche effect at work.

Verify a webhook-style JSON payload the way GitHub or a similar provider would sign it, using HMAC-SHA256 with a shared webhook secret.

  1. Set the algorithm to SHA-256.
  2. Enter whsecret as the secret key.
  3. Enter the exact raw body {"action":"opened","number":1} as the message, with no extra spaces or re-formatting.
  4. Compare the generated digest to the value in the signature header sent by the provider.

Result: 6b1b6a1ca357dcb6be868197ca2eaaa2090ae07f9f0be3c0f2bd6438586e3e1b. If the provider sends a header like sha256=6b1b6a1c..., the payload is authentic and untouched.

HMAC output length by hash algorithm

AlgorithmOutput bytesHex charactersNotes
HMAC-MD51632Broken hash underneath, legacy compatibility only
HMAC-SHA12040Legacy, avoid for new designs
HMAC-SHA2563264Widely used default, matches JWT HS256
HMAC-SHA51264128Longest, strong security margin, matches JWT HS512

Common HMAC use in popular webhook and API providers

ProviderTypical algorithmWhere the signature appears
GitHubHMAC-SHA256X-Hub-Signature-256 header
StripeHMAC-SHA256Stripe-Signature header
SlackHMAC-SHA256X-Slack-Signature header
AWS (SigV4)HMAC-SHA256 chainedAuthorization header, derived signing key
PayPal / ShopifyHMAC-SHA256X-Shopify-Hmac-SHA256 or similar header

HMAC vs a plain hash vs a digital signature

PropertyPlain hash (e.g. SHA-256)HMACDigital signature (e.g. RSA, ECDSA)
Needs a secret keyNoYes, one shared keyYes, a private key
Detects accidental changeYesYesYes
Proves who sent itNoYes, if only sender and receiver know the keyYes, publicly verifiable
Anyone can verify without secretsYesNo, verifier needs the same keyYes, with the public key
Typical useFile integrity checksWebhooks, API signing, JWT HS256Certificates, code signing, JWT RS256

Common mistakes to avoid

  • Confusing HMAC with a plain hash. A plain SHA-256 hash uses no key, so anyone can recompute it. HMAC requires the secret key, which is what makes it an authentication code. Make sure you are using the keyed function, not a bare digest, when a provider asks for an HMAC signature.
  • Mismatched key encoding. This tool treats the key as raw UTF-8 text. If the other side expects the key as base64 or hex bytes, decode it first. A different byte interpretation of the same key string produces a completely different HMAC.
  • Hashing the wrong message bytes. Webhook providers usually sign the exact raw request body, sometimes joined with a timestamp. Re-serializing, pretty-printing, or changing key order in the JSON changes the bytes and breaks the match. Sign the original bytes exactly as received, before any parsing.
  • Comparing signatures with a simple equality check. In production code, compare HMAC values with a constant-time comparison function, not a naive string equality check. An early-exit comparison can leak timing information about how many leading characters matched, which is a real (if narrow) side-channel risk.
  • Assuming HMAC output is base64 by default. This tool and most libraries return raw HMAC bytes, which can be shown as hex or as base64. AWS and some webhook providers expect base64, while GitHub and Stripe expect hex prefixed with sha256=. Check the provider docs before assuming the format.
  • Reusing a weak or guessable secret key. HMAC security depends entirely on the secrecy and randomness of the key. A short, predictable, or leaked key can be brute-forced or guessed even though the hash algorithm itself is strong. Use a long, randomly generated key and rotate it if it may have leaked.

Glossary

HMAC
Hash-based Message Authentication Code. A keyed hash that proves both the integrity and the authenticity of a message.
Secret key
A shared value known to both the sender and the verifier. Knowledge of the key is what lets a party create or check an HMAC.
Digest
The fixed-length output of a hash or HMAC, shown here as a hexadecimal string.
Hexadecimal
A base-16 text representation where each byte is written as two characters from 0 to 9 and a to f.
Avalanche effect
The property that a tiny change in the input flips about half the output bits, making outputs look unrelated.
Web Crypto API
A browser-native cryptography interface (SubtleCrypto) that provides hashing, HMAC, and other primitives without a third-party library.
Constant-time comparison
A way of comparing two secrets, such as HMAC digests, that always takes the same amount of time regardless of where they first differ, to avoid leaking information through timing.
Block size
The internal chunk size a hash function processes at a time (64 bytes for SHA-1 and SHA-256, 128 bytes for SHA-512), used when HMAC pads or hashes the key down to size.

Frequently asked questions

What is the difference between a hash and an HMAC?

A hash like SHA-256 takes only a message and can be computed by anyone, so it detects accidental change but not forgery. An HMAC also mixes in a secret key, so only someone who knows the key can produce or verify the value, which proves authenticity as well as integrity.

Which HMAC algorithm should I choose?

HMAC-SHA256 is the safe default and matches what most webhook providers, APIs, and JWT HS256 tokens use. Choose SHA-512 if a specification asks for it or you want a longer tag. Use SHA-1 only to interoperate with older systems, because SHA-1 is considered legacy.

Is my secret key or message sent anywhere?

No. The HMAC is computed entirely in your browser with the Web Crypto API. Nothing you type is uploaded, logged, or transmitted, which makes the tool safe for testing real keys on a machine you trust.

Why does HMAC-SHA1 still look fairly secure here?

HMAC-SHA1 has held up better than plain SHA-1 because the key and the inner and outer pads make the known collision attacks on SHA-1 impractical to use against HMAC. Even so, new systems should prefer SHA-256 or SHA-512 to stay aligned with current guidance from NIST and most security standards.

How do I verify a signature I received?

Put the exact same message bytes and the same secret key into this tool, choose the matching algorithm, and compare the generated hex with the signature you received. If every character matches, the signature is valid and the message has not been tampered with.

Can I get the output in base64 instead of hex?

This tool shows the result in hexadecimal because that is the most common format for signatures like GitHub and Stripe webhooks. To convert, decode the hex back to bytes and encode those bytes as base64 using a separate base64 tool, or use whichever format your provider documents.

Is HMAC the same thing as the HS256 algorithm in a JWT?

Yes. HS256 in a JSON Web Token is exactly HMAC-SHA256 computed over the base64url-encoded header and payload, using the JWT signing secret as the HMAC key. This tool can reproduce that digest if you build the same input string by hand.

Does the length of my secret key matter?

HMAC accepts keys of any length, but very short keys are easier to guess or brute-force even though the algorithm itself is not weakened mathematically. Keys shorter than the hash block size get padded, and keys longer than the block size get hashed down first, but security in practice depends on using a long, random key.

Can two different messages produce the same HMAC?

In theory yes, because the output space is finite, but for SHA-256 or SHA-512 the chance of an accidental collision is astronomically small and no practical attack is known. This is different from HMAC-MD5, where the underlying hash has known weaknesses.

Why is my HMAC different from another online tool for the same inputs?

The most common cause is key encoding: one tool may read the key as UTF-8 text while another reads it as hex or base64 bytes. Whitespace, invisible characters, or a trailing newline in the message can also change the bytes being hashed. Check both fields carefully before assuming the algorithm is wrong.