About the HMAC Generator
Payment gateways, webhooks and APIs often sign requests with an HMAC so the receiver can confirm they came from someone holding the shared secret and were not altered. This HMAC generator calculates the signature for a message and key with SHA-256, SHA-1, SHA-384 or SHA-512, in hexadecimal or Base64, which helps when debugging signature mismatches. Your key stays in your browser, but use test keys where possible. Paste the exact message the service signs, byte for byte, since a single extra space or line break changes the signature completely.
HMAC is everywhere in web development. Stripe, GitHub, Shopify, Slack and many other services sign their webhooks with HMAC-SHA256 so you can confirm a request really came from them, and APIs such as AWS use HMAC to sign requests. When a signature check fails, recomputing it here with the exact raw body and secret is the quickest way to find out why.
Keys can be entered as plain text, hexadecimal or Base64, matching how services usually present secrets. Remember that the exact bytes matter: a reformatted JSON body, an extra newline or a key with stray spaces produces a different signature. The calculation uses Web Crypto in your browser, and the key never leaves your device.
To create signed JSON Web Tokens, use the JWT encoder, and to inspect them, the JWT decoder. For plain hashes without a key, try the SHA-256 generator. Results update as you type, so you can adjust the message or the key and see the effect at once.
How to use the HMAC Generator
- Enter the messagePaste the exact message or request body that was signed.
- Enter the secret keyType or paste the key and choose whether it is text, hex or Base64.
- Choose the algorithmSHA-256 is the most common; SHA-1, SHA-384 and SHA-512 are available.
- Compare or copyCopy the signature, or paste the one you received to compare.
HMAC Generator features
- HMAC with SHA-1, SHA-256, SHA-384 and SHA-512
- Text, hex or Base64 keys
- Hex and Base64 output
- Compare with a received signature
- Live update as you type
- UTF-8 message handling
- Uses the browser's Web Crypto
- Keys never leave your device
Common uses
- Debugging webhook signature checks
- Signing API requests during development
- Verifying test vectors in unit tests
- Learning how message authentication works
- Generating signed tokens for internal tools
HMAC in practice: debugging a webhook signature, header formats, timestamps and replay attacks, raw bodies, key rotation and signed links
HMAC signatures protect webhooks, API requests and download links by proving that a message came from someone holding a shared secret and was not changed. When a signature check fails, the cause is almost always a small difference in the exact bytes being signed. This guide works through a webhook signature, explains how providers format their signature headers, and covers timestamps, raw request bodies, constant-time comparison, key rotation and signed download links.
A worked example: a webhook signature
A payment service sends this body, with the test secret whsec_test_123:
{"order_id":"1042","status":"paid"}
The HMAC-SHA256 signature in hexadecimal is 6083343826b01d7d9a89e667fc643f8aac44ef0b146bb2bcb3b0c1d82a5420f5. If a framework parses the body and writes it out again with spaces after the colons and commas, the signature of the reformatted text becomes ad3f0d0c73c0b2effdbd4edaeaf7d6e2040637d2b0cc37a3d0f335e47c304958, which no longer matches. The data is the same, but the bytes are not, and HMAC signs bytes.
Header formats
Providers present signatures in different ways. Some send plain hexadecimal, some send Base64, which for the example above is YIM0OCawHX2aieZn/GQ/iqxE7wsUa7K8s7DB2CpUIPU=, and GitHub adds a prefix, sending a header beginning with sha256= followed by the hex value. Strip any prefix and compare in the same encoding the provider uses, as described in its documentation.
Timestamps and replay attacks
A valid signed message could be captured and sent again later. To prevent this, many providers include a timestamp in the signed content, for example signing the timestamp, a full stop and the body together, and recommend rejecting events older than a few minutes. Your verification code should check the timestamp as well as the signature, and your server clock should be kept accurate.
Capturing the raw body
Web frameworks usually parse JSON before your code sees it. For webhook routes, configure the framework to keep the raw body, for instance with Express's raw body parser on that route, and compute the HMAC from those exact bytes. Parsing and re-serialising, even with the same library, may change spacing, key order or number formatting.
Constant-time comparison
Comparing signatures with an ordinary equality check can leak, through tiny timing differences, how many leading characters matched. Use the comparison functions designed for this, such as crypto.timingSafeEqual in Node.js or hmac.compare_digest in Python. They take the same time regardless of where the strings differ.
Rotating secrets
When a webhook secret must be changed, for example after a staff member leaves, providers often allow two secrets to be active briefly. Verify against both during the changeover, then remove the old one. Store secrets in environment variables or a secrets manager rather than in code, so rotation does not require editing and redeploying source files.
Signed download links
The same technique protects private downloads. A server creates a link containing the file path, an expiry time and an HMAC of both, using a secret only the server knows. When the link is used, the server recomputes the HMAC and checks the expiry, so links cannot be altered to reach other files or used after they expire.
Common mistakes
- Verifying a parsed and re-serialised body instead of the raw bytes.
- Comparing a hexadecimal signature with a Base64 one.
- Ignoring timestamps and accepting replayed messages.
- Comparing signatures with ordinary string equality.
Related tools
To read webhook timestamps, use Timestamp Converter. To decode Base64 signatures, try Base64 Decoder, and to view webhook bodies clearly, JSON Formatter.
Reproducing the provider's example
Many providers' documentation includes a sample payload, a sample secret and the expected signature. Reproducing that exact example here before writing any code confirms that you understand the format: which encoding the signature uses, whether a timestamp is included and how the parts are joined. If you cannot match their example, your code will not match their real signatures either.
Signing your own webhooks
If your platform sends webhooks to customers, sign them in a way that is easy to verify: include a timestamp header, sign the timestamp together with the body using a per-customer secret, and document the format with a short code sample. Clear documentation saves your support team from countless verification questions.
Request signing in cloud APIs
Some cloud APIs, such as AWS with its Signature Version 4 scheme, derive a signing key through a chain of HMAC calculations involving the date, region and service before signing each request. This is why official SDKs are strongly recommended for such services: signing by hand is possible but easy to get subtly wrong.
Logging failed checks
Log why each verification fails, such as a missing header, an expired timestamp or a signature mismatch, but never log the secret itself. A sudden rise in failures usually means a configuration change, such as a rotated secret, rather than an attack, and clear logs make the cause obvious within minutes.
Privacy
Signatures are calculated with your browser's Web Crypto. Your message and secret key never leave your device, but use test secrets wherever possible.
Frequently asked questions
What is HMAC?
HMAC is a way to sign a message with a secret key using a hash function. Only someone with the same key can produce the same signature, so a matching HMAC proves the message is authentic and unchanged.
How do I verify a webhook signature?
Take the raw request body exactly as received, not reformatted, and the webhook secret, compute HMAC-SHA256 here, and compare it with the signature header. Many services add a timestamp or prefix to the signed text, so check their documentation for the exact format.
Should the key be text, hex or Base64?
Use the format your service shows. Most webhook secrets are plain text strings, while some APIs give keys as hex or Base64. Choosing the wrong format changes the key bytes and the signature.
Why doesn't my HMAC match?
The usual causes are a modified body, such as pretty-printed JSON instead of the raw payload, a trailing newline, the wrong key format, or comparing hex with Base64. Check each of these in turn.
Which algorithm should I use?
HMAC-SHA256 is the standard choice and secure. HMAC-SHA1 is still safe as a MAC but discouraged for new systems; use it only when a service requires it.
Is HMAC the same as encryption?
No. HMAC does not hide the message; it only proves who created it and that it is unchanged. To keep a message secret, encrypt it as well, for example with the text encryption tool.
Is my secret key uploaded?
No. Everything is calculated by code running in this page on your own device. Your text, files and keys are never uploaded, stored or logged, so it is safe to use with private data.