What Is HMAC?
HMAC is a message authentication code computed with a shared secret and a hash function. For example, a webhook receiver can check whether a payload matches the tag created by a service that knows the secret.
Need a digest without a shared secret? Use the SHA-256 hash generator for exact text, the OpenSSL-compatible hash generator for bulk hashing, or the file hash generator and checker for file checksums.
How to generate an HMAC secret key
A secret key is the private input shared by the sender and receiver. The HMAC signature is the output calculated from that key and a message. Generating a signature does not generate a new secret key.
For a new HMAC-SHA256 integration, generate 32 cryptographically random bytes unless your protocol specifies otherwise. This matches the minimum key-length recommendation in RFC 2104, section 3. When verifying an existing API or webhook signature, use the secret issued for that integration; a newly generated key will not match.
Generate a secret locally with OpenSSL:
openssl rand -hex 32
This produces 64 hexadecimal characters representing 32 random bytes. Agree with the receiving system whether those characters are the literal secret text or an encoding of binary key bytes. Store the secret in a secrets manager, keep it out of source control and logs, and rotate it according to your integration's requirements.
Text keys versus Hex or Base64 keys
This tool reads the message and shared secret as UTF-8 text. It does not decode a hexadecimal or Base64 key. For example, entering 4a656665 uses those eight text characters; it does not use the four bytes of Jefe. The Hex/Base64 selector controls the result encoding only.
If your integration requires a binary key represented as hex, decode it locally before calculating the HMAC:
import hmac
from pathlib import Path
key = bytes.fromhex(Path("key.hex").read_text().strip())
message = Path("message.txt").read_bytes()
print(hmac.digest(key, message, "sha256").hex())
Save the OpenSSL output in key.hex and use the exact message bytes in message.txt. For a Base64-encoded binary key, decode it with base64.b64decode instead. The online Generate and Verify actions send your inputs to DevGlan's server for processing; use the local examples for production secrets or sensitive messages.
How HMAC Works:
- Components:
- Message:The data you want to authenticate.
- Key:A secret key known only to the sender and the receiver.
- Hash Function:Typically, a cryptographic hash function like SHA-256 or SHA-512.
- Calculation
- Initialization:Choose an appropriate hash function (e.g., SHA-256) and a secret key K.
- Key ModificationIf necessary, modify the key to fit the hash function's block size.
- PaddingIf needed, pad the key so it fits the block size of the hash function.
When Should You NOT Use HMAC?
HMAC is not suitable for password storage or password hashing. If you are storing user passwords or deriving encryption keys from passwords, use a password hashing function instead:
- Argon2 password hash generator - Modern, memory-hard and GPU-resistant
- PBKDF2 hash generator - Widely supported key derivation function
HMAC-SHA256 worked example
Use this public test vector from RFC 4231, test case 2 to check your calculation. The short key is for testing only.
- Message (UTF-8):
what do ya want for nothing? - Shared secret (UTF-8):
Jefe - Hash function: SHA-256
- Result format: Hex
Enter the message and key without quotes or a trailing newline. The expected 64-character Hex signature is:
5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843
After generating it, choose Send to verification, then Verify HMAC. You should see Valid HMAC. Add a space to the verification message, keep the same signature, and verify again: the result should be Invalid HMAC.
Reproduce the same signature in Python
import hmac
key = b"Jefe"
message = b"what do ya want for nothing?"
expected = "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"
mac = hmac.digest(key, message, "sha256")
print(mac.hex())
print(hmac.compare_digest(mac, bytes.fromhex(expected))) # True
Reproduce the same signature with OpenSSL
In a POSIX shell such as Bash, use printf to avoid adding a newline:
printf '%s' 'what do ya want for nothing?' | openssl dgst -sha256 -hmac 'Jefe'
The digest after OpenSSL's output label should match the Hex signature above. Use this command with the public test key only; command-line arguments can appear in shell history or process listings.
Usage Guide - HMAC-SHA256 Online Tool
- Under Generate HMAC, enter the message and a test secret, then leave the hash function set to SHA-256.
- Choose Generate HMAC to see the Hex tag in Result. For Base64, change the selector beside Result and generate again.
- Choose Send to verification to try the generated tag. To check a tag from another source, enter the original message and shared secret, then select the matching hash function under Verify HMAC.
- Check the Received MAC (Hex or Base64) field, pasting the external tag if needed, then choose Verify HMAC.
Why does HMAC signature verification fail?
Verification recomputes the signature from the original message, shared secret and hash function. A mismatch means at least one input or encoding differs. Check these common causes before changing your implementation:
| Possible cause | What to check |
|---|---|
| Different secret | Use the signing secret for the correct endpoint and environment. Check whether the provider rotated it. An API access token may not be the webhook signing secret. |
| Changed message bytes | Preserve spaces, Unicode encoding and line endings. A trailing newline or CRLF instead of LF changes the signature. |
| Reformatted JSON | Use the original raw request body when the provider signs it. Parsing and serializing JSON can change whitespace, key order and escapes. |
| Wrong key encoding | Determine whether the provider uses literal text or decoded Hex/Base64 bytes. This tool accepts UTF-8 text keys; use a local example for binary keys. |
| Wrong algorithm | Match HMAC-SHA256, HMAC-SHA384 or HMAC-SHA512 to the sender. A plain SHA-256 digest is not an HMAC. |
| Wrong signature encoding | Paste a full Hex or standard padded Base64 MAC. Base64url and truncated tags are not accepted by this verifier. Hex and Base64 represent bytes differently. |
| Header prefix or multiple signatures | Extract the signature value according to the provider's documentation. Do not paste an entire header such as sha256=... or a comma-separated list into Received MAC. |
| Missing timestamp or signing fields | Some providers sign a timestamp, separator and body, or a canonical request containing several fields. Reproduce that exact signing input rather than assuming the body alone is signed. |
Verifying a webhook in your application
Follow the provider's signing specification: obtain the exact signed bytes, compute the HMAC using the shared secret, decode the received signature, and compare the MAC bytes with a constant-time comparison such as Python's hmac.compare_digest. Reject malformed signatures before comparison. A valid HMAC does not establish freshness: enforce the provider's timestamp tolerance and replay protections separately.
This tool checks whether the supplied message and signature match. It does not fetch webhook requests, parse provider headers, or enforce timestamp and replay policies.
Comparison between Hashing and Mac tools
| Algorithm | Purpose | Use for Passwords? |
|---|---|---|
| HMAC-SHA256 | Message authentication | ❌ No |
| Poly1305 | Message authentication | ❌ No |
| Argon2 | Password hashing | ✅ Yes |
| PBKDF2 | Password hashing / KDF | ✅ Yes |
If you need a modern and fast MAC algorithm, you should use: Poly1305 MAC Generator- High-performance MAC commonly used with ChaCha20.
❤️ Liked this tool?
If it saved you time, consider buying me a coffee to support future improvements.