A payment provider, a code host or a form service sends your server a webhook: an HTTP request announcing that something happened. Attached is a signature header, produced with a secret you and the sender share. Your job is to decide whether the request really came from them and arrived unchanged, before you act on it.
Done right, this check is simple and strict. Done slightly wrong, it rejects every genuine webhook or waves forged ones through. This guide walks through the receiver's workflow using the free HMAC Generator on Ovatly, which signs on your device so you can test a real payload by hand.
Contents
- Quick answer
- What the signature is actually checking
- The raw bytes rule
- Hex or Base64: match the sender's encoding
- How to verify a webhook signature, step by step
- Worked example: signing a known message
- When the signature does not match
- Limitations and honest tradeoffs
- Common mistakes
- FAQs
- Conclusion
- References
Quick answer
To verify a webhook signature: take the payload bytes exactly as they arrived, with no parsing or re-printing, sign them with the shared secret using the HMAC Generator, and compare your signature with the one in the sender's header, in the same encoding the sender used. A match means the payload is unchanged and was signed by a holder of the secret. A mismatch is almost always a byte-level problem, most often JSON re-serialised before signing.
What the signature is actually checking
Before sending, the sender runs the payload through an HMAC with the shared secret and puts the result in a header. Your verification repeats that computation on what you received. If the two signatures agree, two things follow: the payload you hold is byte for byte the payload that was signed, and whoever signed it held the secret.
Notice what the check rests on. The signature covers the exact bytes, not the meaning of the message. Two payloads can carry identical information yet be different byte strings, and only one will verify. Most webhook debugging is really byte debugging, which is why the next section is the spine of this workflow.
The raw bytes rule
Webhook payloads are usually JSON, and JSON is where signatures go to die. When your code parses JSON into an object and prints it back out, the result rarely matches what arrived: spaces after colons come and go, keys may be reordered, numbers may be reformatted. Each change produces different bytes, and different bytes produce a different signature.
So the rule is absolute: capture the request body as a raw string before any parsing, and sign that. In your own code this means reading the body before the framework's JSON parser consumes it. When testing by hand, it means pasting the payload exactly as it appears in the request, character for character, including any trailing newline if one is genuinely part of the body. Copy it out of a tool that pretty-prints it and you have already changed it.
Hex or Base64: match the sender's encoding
The generator shows every signature in two forms, hex and Base64. These are not two signatures; they are the same bytes written in two encodings. Senders pick one for their header, and your comparison has to happen in that encoding, or after converting one side to the other.
Check the sender's documentation or a known-good example to learn which encoding they send, then copy your result in that format. A surprising share of "the signature never matches" reports are two correct signatures compared across encodings. The same applies to the key: if the secret is issued as hex text, it must be decoded as hex, not typed in as ordinary characters, or you are signing with a different key.
How to verify a webhook signature, step by step
- Capture the raw payload exactly as received, before parsing, and copy the signature value from the header.
- Open the HMAC Generator and paste the raw payload as the message, byte for byte.
- Enter the shared secret key, in the format it was issued: plain text as text, hex as hex.
- Pick the hash the sender uses, SHA-256, SHA-384 or SHA-512, and click Compute HMAC.
- Copy the signature in the encoding the sender's header uses, and compare it with the header value character by character. Equal means verified; different means work through the mismatch checklist below.
The signing happens on your device through Web Crypto, and nothing is transmitted. Even so, use a test secret where you can, and never paste production secrets into any tool on a machine you do not trust.
Worked example: signing a known message
Before trusting the workflow on a live webhook, prove it on a published test value. Use the message "The quick brown fox jumps over the lazy dog" and the key "key". With HMAC-SHA-256, the generator returns:
f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8
If your run produces this value, your message bytes, key handling and hash choice are all correct. Now add a single trailing newline and sign again: the signature changes completely. That one invisible character is the whole lesson. A real payload differs from its re-serialised version by far more than one character, so if your verification signs anything except the raw body, it will fail exactly this way.
When the signature does not match
Work through the causes in order of likelihood. First, the bytes: did anything parse, trim, pretty-print or re-encode the payload before you signed it? Second, the key: is it the right secret for this sender and environment, read in the format it was issued in? Third, the hash and the encoding: are you computing the same variant the sender used, and comparing hex with hex or Base64 with Base64?
Only after those three should you consider that the payload was altered in transit or signed with a different secret. In practice the mundane causes explain nearly every mismatch, and all are fixable on your side once you know which bytes each side signed.
Limitations and honest tradeoffs
This workflow verifies one payload at a time, by hand. That is the right tool for testing an integration and hunting a mismatch, and the wrong tool for production traffic, where the same steps belong in server code, running on every request. The manual check is not weaker cryptographically; it is simply not automation.
Verification also has a boundary. A matching signature proves the payload came from a holder of the shared secret and was not changed. Because the secret is shared, it cannot prove which holder signed it, and anyone who can verify can also sign. And an HMAC does not encrypt anything: the payload travelled in readable form, protected by the transport, not by the signature.
Common mistakes
- Signing the parsed object. The single most common failure. Parse for your business logic, but sign the raw body.
- Copying the payload from a pretty-printer. Log viewers and JSON formatters change the bytes. Copy from the raw request.
- Comparing across encodings. Hex against Base64 never matches. Convert, or copy the matching format.
- Treating a hex key as text. The characters of a hex key are not the key. Format errors here produce confident, wrong signatures.
- Assuming a mismatch means an attack. It almost always means a byte-level slip in your own pipeline. Rule out the mundane causes first.
FAQs
Why must I sign the raw payload instead of the parsed JSON? Parsing and re-printing JSON changes the bytes: spacing, key order and number formats can all shift. The sender signed the bytes they transmitted, so your signature has to be computed over those same bytes. Sign the parsed version and you are verifying a message nobody sent.
Which encoding should I compare the signature in? The one the sender used. Hex and Base64 are the same signature bytes written in two encodings, so either works as long as both sides match. Copy the format the sender's header uses, or convert your result before comparing.
What does a mismatch usually mean? Almost always a byte-level difference: the payload was re-serialised, a trailing newline crept in, the encoding differs, or the key was handled in the wrong format, such as a hex key treated as plain text. A genuinely wrong key or a tampered payload is possible, but it is the last explanation to reach for, not the first.
Can I decrypt the webhook signature to check its contents? No. An HMAC cannot be decrypted and contains nothing to read. The only way to verify one is to sign the received payload yourself with the shared secret and compare your signature with the one in the header.
Is checking one webhook by hand enough for a production system? No. Production systems automate exactly these steps in code on every request. Checking one payload by hand is for testing an integration and debugging a mismatch, which is what this tool is for.
Conclusion
Webhook verification stands or falls on one discipline: sign exactly what arrived. Keep the raw bytes untouched, match the sender's hash and encoding, and the HMAC Generator gives you a verdict you can trust. For the thinking behind the signature, our companion guide on HMAC vs a plain hash explains what the secret key adds. For more in this series, see our Security and Privacy guides.
References
- RFC 2104, HMAC: Keyed-Hashing for Message Authentication: https://www.rfc-editor.org/rfc/rfc2104
- NIST FIPS 198-1, The Keyed-Hash Message Authentication Code (HMAC): https://csrc.nist.gov/pubs/fips/198-1/final