— — enter key + message — —— — enter key + message — —— — enter key + message — —— — enter key + message — —About HMAC Generator
HMAC feeds a message together with a secret key into a hash function to produce an authentication code that verifies both data integrity and origin. It powers webhook verification, API request signing, and the HS256 algorithm in JWTs. This tool uses the browser-native Web Crypto API to compute HMAC locally with your key, supporting SHA-1/SHA-256/SHA-384/SHA-512 and Hex or Base64 output. For example, signing the message hello with key secret produces a 64-char hex HMAC-SHA256 signature ready for API request verification. Proving that a message was not altered and did come from a party holding the shared secret calls for a message authentication code. It differs from a signature: a signature is issued with a private key and verified with a public one, allowing many verifiers and non-repudiation, whereas a code is computed and verified with the same key, restricting it to the two parties sharing that key, in exchange for speed and simplicity. Fundamentally, a code is not just a hash over the key concatenated with the message. Naive concatenation is vulnerable to length extension, where an attacker derives a valid digest for the original message plus extra bytes without knowing the key. Proper constructions wrap the key through two passes before hashing, which is why a standard implementation must be used rather than hand-rolled concatenation. Practical notes: The key must be high-entropy random data, never a passphrase or any guessable string. Compare digests in constant time, because a byte-by-byte comparison leaks the matching prefix through response timing and can in principle be exploited remotely to recover the correct digest. The signed input must cover everything worth protecting, including method, path, timestamp and a body digest, since protecting only part leaves a gap for tampering; including a timestamp with a tolerance window also mitigates replay. Limits: A code guarantees integrity and origin, not confidentiality, since the message stays in the clear, so secrecy requires encryption alongside. It also does not answer who sent a message in a multi-party setting, which needs asymmetric signatures. Implementation has its own traps: a key longer than the hash block size is compressed first, which matters when diagnosing why two sides disagree. The encoding must be agreed, since hex on one side and text output on the other produce different results. Data and privacy: a code protects sensitive endpoints, and a leaked key is equivalent to losing the ability to sign. This tool computes in the browser without uploading the key or the message; for production keys, work offline and rotate them periodically to limit the impact of a leak. Two misuses: Concatenating the key with the message and hashing, a construction vulnerable to length extension where an attacker derives a valid digest for the original plus extra bytes without the key, so a standard implementation is required. And comparing digests byte by byte, which leaks the matching prefix through response timing and can in principle be exploited remotely; constant-time comparison is mandatory.
How It Works Internally
A MAC wraps the key through two passes before hashing, so it is not "a hash with a salt" but a construction resistant to length extension: an inner pass hashes the message under the key, and an outer pass hashes that digest under the key again. Verification must compare in constant time, because a byte-by-byte comparison leaks the matching prefix through response timing.
Key "key", message "The quick brown fox"A fixed hex digest; changing the message to "The quick brown foX" gives a completely different value (avalanche)Measured on This Page
| SHA-1 matches | effcdf6ae5eb2fa2d27416d5f184df9c259a7c79, identical to the RFC 4231 value |
|---|---|
| SHA-256 matches | 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843, identical |
| SHA-384 matches | af45d2e376484031617f78d2b58a6b1b9c7ef464f5a01b47e42ec3736322445e…, identical |
| SHA-512 matches | 164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea250554…, identical |
| Implementation | Browser-native crypto.subtle (Web Crypto) with no third-party JS crypto library, so the primitive itself comes from the platform |
A detail that catches people out: the secret is read as UTF-8 text, so a password typed in the box and the same string sent as bytes by a server must be byte-identical — an extra space, a trailing newline or a different Unicode normalisation changes every bit of the output. The 4 algorithms also differ in output length (20, 32, 48 and 64 bytes), which matters when a header or database column has a fixed width. Size the key at least as long as the digest, and keep it random rather than memorable.
How to Use
- Open "HMAC Generator"
- Enter the shared key and the message in the two editors
- All four digests are computed automatically
- Find the algorithm your server uses and copy from its row
- Compare byte for byte against the server, using one encoding
Use Cases
- Verify webhooks — Recompute HMAC-SHA256 with the platform secret and compare it to the signature header to confirm authenticity.
- Sign API requests — Build the string-to-sign per the vendor spec and generate an HMAC to send as an auth header.
- Debug JWT HS256 — Manually reproduce the HMAC over header.payload to diagnose signature verification failures.
- Cross-check implementations — Confirm an HMAC from a backend language like Java or Python matches the standard output.
- Sign idempotency keys — HMAC parameters such as order IDs to get a reproducible, tamper-evident check value.
- OAuth signature — Generate the HMAC digest for OAuth 1.0 parameter strings to authenticate API requests.
- Payload integrity — HMAC the request body with a shared key to produce a checksum for tamper detection.
FAQ
How is HMAC different from plain SHA-256?
Anyone can compute a plain hash, so it proves nothing about origin. HMAC mixes in a shared secret, and without that key you cannot produce the correct value, which authenticates that the message came from the key holder.
Should the key be text or Hex?
It depends on the server contract. Most webhooks use a UTF-8 text key, but some APIs require decoding the key from Hex/Base64 into raw bytes first. The two yield different results, so match your counterpart.
Which hash algorithm should I pick?
SHA-256 is the default recommendation, balancing security and speed. SHA-1 is only for legacy compatibility and is discouraged for new projects; use SHA-384/512 when you want a larger security margin.
What matters when comparing signatures?
Production code should use a constant-time compare to avoid leaking information through timing differences. This tool is for manual checks; verify the copied value securely in your code.
Is differing case or encoding a problem?
The raw HMAC is bytes; Hex case and Base64 are just representations. Normalize the encoding before comparing rather than treating a case difference as a mismatch.
My local signature does not match the server. Where do I start?
Confirm how the key is represented as bytes: if the server decodes it from a hex string while you use the literal text, the two can never agree. Then confirm the signed content matches byte for byte, since whitespace, line endings and field order all change the result. Finally confirm whether the output encoding is hex or Base64, the easiest thing to misread in a log.
How is this different from concatenating the key with the message and hashing?
Naive concatenation is vulnerable to length extension: an attacker can derive a valid digest for the original message plus extra bytes without knowing the key. Proper constructions wrap the key through two passes before hashing, which resists that attack. Use a standard implementation, because a hand-rolled concatenation is insecure even when the output looks plausible.
What is the difference between HMAC and a plain hash?
Anyone can compute a plain hash; only someone holding the key can produce the matching HMAC, so it verifies both integrity and origin. API signatures (AWS, WeChat Pay) are HMAC: the server recomputes with the shared key and rejects mismatches.