Generate or verify an HMAC-SHA256 (or SHA-384, SHA-512, SHA-1) with a text, hex or Base64 secret key. Enter the message and key in the format your system uses, and the HMAC updates as you type. Paste an expected value to check it: if it doesn't match, the tool tells you which setting would make it match. HMAC proves a message wasn't changed by someone without the key; it doesn't hide the message.
Message: 0 bytes
Use a test key. Don't paste production secrets into any website, including this one.
Enter a secret key.
This check runs in your browser. Web Crypto doesn't promise a constant-time comparison, and a web page can't guarantee one. That doesn't matter here, because nobody can time a check on your own device. On your server, use a constant-time function: Node crypto.timingSafeEqual, Python hmac.compare_digest, PHP hash_equals, Go hmac.Equal, Java MessageDigest.isEqual.
Calculations use the Web Crypto API in your browser. Nothing is uploaded or saved.
What is HMAC?
HMAC (Hash-based Message Authentication Code) is a cryptographic construction that combines a secret key with a hash function to produce a message authentication code. Anyone who knows the same secret key can calculate or verify the HMAC for a message.
HMAC helps protect message integrity and authenticity. If the key remains secret, a valid HMAC provides evidence that the message was not modified and was authenticated by someone holding that key. HMAC does not encrypt the message or hide its contents.
HMAC is specified in RFC 2104 and FIPS 198-1. This tool supports the following algorithms:
| Algorithm | Output size | Hex characters |
|---|---|---|
| HMAC-SHA256 | 256 bits (32 bytes) | 64 |
| HMAC-SHA384 | 384 bits (48 bytes) | 96 |
| HMAC-SHA512 | 512 bits (64 bytes) | 128 |
| HMAC-SHA1 (legacy) | 160 bits (20 bytes) | 40 |
HMAC-SHA256 is the default and a suitable choice for most new applications. HMAC-SHA1 may be needed when interoperating with older systems; collision weaknesses in plain SHA-1 do not directly translate into the same attacks against HMAC-SHA1.
How does HMAC work?
HMAC uses a hash function twice with an inner and outer padded version of the secret key. In simplified notation:
HMAC(K, m) = H((K' XOR opad) || H((K' XOR ipad) || m))
Here, K is the secret key, m is the message, H is the selected hash function, and K' is the key processed to the hash function's block size. The inner and outer pads are predefined byte sequences. This design avoids the length-extension problem of simply hashing a secret key followed by a message.
HMAC vs. a plain SHA-256 hash
Anyone can compute the plain SHA-256 hash of what do ya want for nothing? without a key: b381e7fec653fc3ab9b178272366b8ac87fed8d31cb25ed1d0e1f3318644c89c. Hashing the key and message together, SHA-256("Jefe" + message) = 689a1a0f…, isn't safe because of length extension: an attacker can append data and compute a valid hash without knowing the key. HMAC with the key Jefe gives 5bdcc146…, and nobody can produce that value without the key.
What HMAC does and doesn't do
- It authenticates. It doesn't encrypt. The message travels in plain view. For confidentiality, encrypt the message with AES.
- Both sides need the same secret. Anyone who can verify can also create valid HMACs, so an HMAC can't prove to a third party which side sent the message. Use a digital signature for that, with a key pair such as one from the RSA key pair generator.
- It doesn't stop replays on its own. A captured message and HMAC can be sent again. Webhook providers usually sign a timestamp with the body and reject old requests.
Where is HMAC used?
- API requests and webhooks: Authenticating messages exchanged between services.
- Signed tokens: JWT algorithms such as HS256, HS384, and HS512 use HMAC. To decode a JWT and verify its signature, use the JWT tool.
- One-time passwords: HOTP and many TOTP implementations use HMAC.
- Key derivation: HKDF uses HMAC as a cryptographic building block.
- Network protocols: HMAC is used in certain TLS, IPsec, and SSH constructions.
How to use the HMAC generator
- Enter the message in the Message field and choose its format: Text (UTF-8), Hex or Base64. For text, choose CRLF line endings if the original message uses Windows line breaks.
- Enter the shared secret in Secret key and choose its format. It is hidden by default; select Show to check what you typed.
- Choose HMAC-SHA256 (default), HMAC-SHA384, HMAC-SHA512, or HMAC-SHA1 for legacy systems.
- Choose Hexadecimal or Base64 output. The HMAC updates as you type; select Copy to copy it.
- To check a value, paste it into Expected HMAC. Hex in any case, Base64, and a
sha256=prefix all work.
The byte counts under the fields show exactly what is hashed: the key itself is never shown in them.
Key and message formats
The tool works on bytes, so the format decides which bytes are used:
- Text (UTF-8): the characters exactly as typed, never trimmed. A space or line break at the end is part of the key or message.
- Hex: two digits per byte. Spaces, line breaks,
:and one leading0xare ignored. An odd number of digits or another character is an error that names its position. To see the hex bytes of a text key, use the text to hex converter. - Base64: standard (
+/) and URL-safe (-_) alphabets, with or without=padding. To decode a Base64 key and look at it, use the Base64 tool.
An empty key can't be used: the browser's Web Crypto API refuses zero-length HMAC keys, so the tool asks for a key instead. An empty message is fine.
Check HMAC-SHA256 against RFC 4231 test vectors
These are the official HMAC-SHA256 test cases from RFC 4231. Load example fills in the key, message and formats, and pastes the expected value, so you see a green Match. Test case 5 checks a value truncated to 128 bits.
| TC | Key | Message | HMAC-SHA256 (hex) | Load |
|---|---|---|---|---|
| 1 | 0b × 20 Hex | b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7 | ||
| 2 | Jefe Text | 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843 | ||
| 3 | aa × 20 Hex | 773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe | ||
| 4 | 0102…1819 (25 bytes) Hex | 82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b | ||
| 5 | 0c × 20 Hex | a3b6167473100ee06e0c796c2955552b (first 128 bits) | ||
| 6 | aa × 131 Hex | 60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54 | ||
| 7 | aa × 131 Hex | 9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2 |
The same key typed in the wrong format gives a different result. Test case 1 with the key entered as the text 0b0b…0b (40 characters) instead of 20 hex bytes gives 0dff03ee…f96b, not b0344c61…cff7. In that case the tool shows a hint that the key looks like Hex.
HMAC-SHA256 with OpenSSL and curl
Every command below was run with OpenSSL 3 and gives the output shown.
Text key. Use printf '%s', not echo, because echo adds a newline:
printf '%s' 'what do ya want for nothing?' | openssl dgst -sha256 -hmac 'Jefe'
# SHA2-256(stdin)= 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843
echo 'what do ya want for nothing?' | openssl dgst -sha256 -hmac 'Jefe'
# SHA2-256(stdin)= 8cc1a9739eea9fe97321dba825363677fed3f8cbc330fa892ad5466a7fd5438e ← includes "\n"
Hex key (raw bytes):
printf '%s' 'Hi There' | openssl dgst -sha256 -mac HMAC -macopt hexkey:0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
# SHA2-256(stdin)= b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7
Base64 key: convert it to hex first:
KEY_HEX=$(printf '%s' 'CwsLCwsLCwsLCwsLCwsLCwsLCws=' | openssl base64 -d -A | od -An -v -tx1 | tr -d ' \n')
printf '%s' 'Hi There' | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$KEY_HEX"
# same result as above
Base64 output:
printf '%s' 'what do ya want for nothing?' | openssl dgst -sha256 -hmac 'Jefe' -binary | base64
# W9zBRr9gdU5qBCQmCJV1x1oAPwidJzmDnexYuWTsOEM=
Sign a webhook-style request with curl:
BODY='{"event":"ping","id":42}'
KEY_HEX=0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
SIG=$(printf '%s' "$BODY" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$KEY_HEX" -r | cut -d' ' -f1)
# SIG = 11054030fb026508c57a8a0608e9d1dddaa97f672c5be223950208c4d7a8bb4e
curl -X POST https://example.com/webhook \
-H 'Content-Type: application/json' \
-H "X-Signature-SHA256: $SIG" \
--data-binary "$BODY"
The Base64 form of the same signature is EQVAMPsCZQjFeooGCOnR3dqpf2csW+IjlQIIxNeou04=. To reproduce it here (Hex key, Text message):
- Sign the exact bytes you send. Use
--data-binary:curl -d @body.jsonstrips line breaks, so a body file that ends with a newline is sent one byte shorter than the one you signed. openssl mac -digest SHA256 -macopt hexkey:… HMAC(OpenSSL 3) works too, but prints uppercase hex.- Keys on the command line end up in shell history and the process list. For real keys, read them from an environment variable or a file.
Security considerations
HMAC security depends on the secret key. For production systems, generate keys using a cryptographically secure random source, store them securely, and never expose them in client-side code. A random 32-byte key is a sound choice for HMAC-SHA256: Random 32-byte key makes one as Hex. Encoding such a key as visible characters is different from using the raw bytes as the key.
This calculator performs the computation locally in the browser with the Web Crypto API; the component does not send the message or key to a hashing server, and doesn't save them. However, website scripts, browser extensions, and compromised devices can still expose sensitive input. Avoid entering live production secrets into public websites. Prefer a trusted local utility or application-side cryptographic library for production work.
To verify HMACs in an application, compare the received and expected values using a constant-time comparison, such as Node crypto.timingSafeEqual, Python hmac.compare_digest, PHP hash_equals, Go hmac.Equal or Java MessageDigest.isEqual. HMAC is not a password-storage algorithm: use Argon2id, scrypt, or bcrypt to store passwords.
Frequently asked questions
What is the difference between HMAC and SHA-256?
SHA-256 is an unkeyed cryptographic hash that anyone can calculate. HMAC-SHA256 combines SHA-256 with a secret key so the result can authenticate a message as well as detect modification.
Can HMAC be decrypted or reversed?
No. HMAC is not encryption and has no decryption operation. Knowing the HMAC does not reveal the original message or secret key. However, predictable messages can still be guessed if the key is known.
Is HMAC-SHA1 still secure?
HMAC-SHA1 remains suitable for many legacy authentication uses despite collision attacks against plain SHA-1. Prefer HMAC-SHA256 for new designs.
Why does my HMAC differ from another tool?
Check the key format first. The key 0b0b…0b read as 20 hex bytes gives b0344c61… for RFC 4231 test case 1, but the same characters read as text give 0dff03ee…. Then check line breaks: a trailing newline, or CRLF instead of LF, changes the result. Finally check the algorithm. Paste the other tool's value into Expected HMAC: if a different setting would match, the tool says which one.
How do I verify a webhook signature?
Compute the HMAC over the exact raw request body, before any JSON parsing or reformatting, with the key in the same format the provider uses (text, hex or Base64). Remove any prefix such as sha256= from the header, then compare the two values on your server with a constant-time function. Many providers also sign a timestamp: include it exactly as they describe, and reject old requests.
Should my HMAC key be text, hex or Base64?
It depends on what the other system decodes. HMAC works on bytes: if the provider's documentation shows the key as hex or Base64 and its code decodes it before use, choose that format here. If its code uses the key string as it is, choose Text. The same characters give different bytes, and so a different HMAC, in each format.
Does the calculator upload my secret key?
No. The HMAC operation runs locally through the browser's Web Crypto API, and the key is not saved. Nevertheless, third-party website scripts and browser extensions can be a risk; do not paste production secrets into online calculators.
Related tools
- JWT decoder and verifier — Check HS256, HS384 and HS512 tokens, which use HMAC.
- SHA-256 hash calculator — Calculate an unkeyed SHA-256 digest.
- Base64 encoder and decoder — Decode Base64 keys and signatures.
- Text to hex converter — See the hex bytes of a text key or message.
- SHA-2 hash calculator — Compare SHA-224, SHA-256, SHA-384, and SHA-512 without a secret key.
Last updated: