About the HMAC Generator
This HMAC generator computes a keyed-hash message authentication code — the signature APIs and webhooks use to prove a message came from someone who knows a shared secret and was not altered on the way. Enter the secret key and the message, choose HMAC-SHA256, HMAC-SHA512, HMAC-SHA1 or HMAC-MD5, and get the signature in hex and Base64 at once.
Developers use it to debug webhook signature checks (Stripe, GitHub, Shopify and Slack all sign payloads with HMAC-SHA256), to build signed API requests, and to confirm that their own code matches a reference value. Paste the signature you received into the compare box to see whether it matches. The key can be given as plain text, hex or Base64, because many services hand out secrets in one of those forms.
The message is signed exactly as typed, as UTF-8 bytes — a single extra space, a different line ending or re-formatted JSON produces a completely different signature, which is the most common reason webhook verification fails. All computation happens in your browser; your key is never sent anywhere.
How to use the hmac generator
- 1Enter the secret key and choose whether it is text, hex or Base64.
- 2Paste the exact message or payload that was signed.
- 3Pick the HMAC algorithm your API or webhook uses.
- 4Copy the hex or Base64 signature.
- 5Optionally paste a received signature to check it matches.
Formula and method
HMAC (RFC 2104, FIPS 198-1) wraps an ordinary hash function H in two passes. The key is first brought to the hash block size B (64 bytes for MD5, SHA-1 and SHA-256; 128 bytes for SHA-512): longer keys are hashed, shorter keys are padded with zero bytes, giving K₀. The inner hash is H((K₀ XOR ipad) followed by the message), and the final signature is H((K₀ XOR opad) followed by the inner hash), where ipad is the byte 0x36 and opad the byte 0x5c repeated B times.
This nested construction is what makes HMAC safe against length-extension attacks that break the naive H(key + message). The output length equals the hash length: 128 bits for MD5, 160 for SHA-1, 256 for SHA-256 and 512 for SHA-512. The message is encoded as UTF-8 bytes exactly as entered.
- K₀
- Key padded (or first hashed) to the block size B
- ipad / opad
- 0x36 / 0x5c repeated B times
- ‖
- Concatenation of byte strings
- H
- Hash function: SHA-256, SHA-512, SHA-1 or MD5
Worked examples
RFC 4231 test vector (HMAC-SHA256)
Test case 2 of RFC 4231 uses the key "Jefe" and the message "what do ya want for nothing?". The 4-byte key is zero-padded to 64 bytes and the two-pass construction gives the published 256-bit signature, which confirms the implementation.
Verify a webhook signature in Base64
The raw JSON body is signed with HMAC-SHA256. The 32-byte result is shown as 64 hex digits and as 44 Base64 characters; the pasted Base64 signature matches, so the payload is authentic and unmodified.
Hex key with HMAC-SHA1 (RFC 2202)
The key is 20 bytes of 0x0b given in hex. RFC 2202 test case 1 for HMAC-SHA1 lists b617318655057264e28bc0b6fb378c8ef146be00, a 160-bit signature.
HMAC-SHA512 of the same message
SHA-512 uses a 128-byte block, so "Jefe" is padded to 128 bytes. The 512-bit signature is 128 hex digits long and matches the HMAC-SHA-512 value in RFC 4231 test case 2.
Frequently asked questions
What is HMAC used for?+
HMAC proves that a message was created by someone holding a shared secret and that it was not changed in transit. It is used to sign webhooks, API requests (such as AWS Signature Version 4), JSON Web Tokens with HS256, session cookies and one-time password algorithms like HOTP and TOTP.
Is HMAC the same as hashing with a key?+
No. Simply hashing key + message is vulnerable to length-extension attacks with SHA-1 and SHA-256. HMAC hashes twice with two different key-derived pads, which makes it a proven message authentication code even when the underlying hash has weaknesses.
Why does my webhook signature not match?+
Most mismatches come from signing different bytes: the framework parsed and re-serialized the JSON, whitespace or line endings changed, or a required prefix was left out (Stripe, for example, signs "<timestamp>.<raw body>", not the body alone). Sign the raw request body exactly as received, and check whether the provider expects hex or Base64.
Is HMAC-SHA1 or HMAC-MD5 still secure?+
As MACs they have no practical break today, because HMAC security does not rely on collision resistance. Still, MD5 and SHA-1 are deprecated for new designs; NIST and most API providers recommend HMAC-SHA256 or HMAC-SHA512.
How long should an HMAC key be?+
RFC 2104 recommends a random key at least as long as the hash output — 32 bytes for HMAC-SHA256 and 64 bytes for HMAC-SHA512. Keys longer than the block size are hashed first, so very long keys add no extra strength.
How do I compute HMAC-SHA256 in code?+
In Python: hmac.new(key, msg, hashlib.sha256).hexdigest(). In Node.js: crypto.createHmac("sha256", key).update(msg).digest("hex"). In the shell: echo -n "msg" | openssl dgst -sha256 -hmac "key". All should match this tool for the same bytes.