How to generate an HMAC SHA256 signature
Enter the message, such as a webhook's request body, and the secret key. Choose SHA-256 or SHA-512 and hex or Base64 output, and the signature appears to copy. The message and secret are encoded as UTF-8 and signed with the browser's Web Crypto API, so neither leaves your device.
HMAC-SHA256(message "hello", secret "secret") hex 88aab3ede8d3adf94d26ab90d3bafd4a2083070c3bcce9c014ee04a443847c0b Base64 iKqz7ejTrflNJquQ07r9SiCDBww7zOnAFO4EpEOEfAs=
Use this pair to check that your own code produces the same result.
What HMAC is
- HMAC combines a secret key with a hash function to sign a message. Anyone with the same key can recompute the signature and confirm the message wasn't changed and came from someone who knows the key.
- It isn't encryption: the message stays readable. It proves integrity and authenticity.
- SHA-256 gives a 64-character hex signature and is what most webhooks use. SHA-512 gives 128 hex characters.
- Hex and Base64 are two ways of writing the same bytes. Use whichever the service you're checking uses.
Verifying a webhook signature
- Take the raw request body exactly as received. Parsing the JSON and serialising it again changes spaces or key order, and the signature no longer matches.
- Some providers sign more than the body. Stripe, for example, signs a timestamp and the body together, so build the same signed string their documentation describes.
- Compute the HMAC with your signing secret and compare it with the header the provider sends. GitHub, for example, sends
X-Hub-Signature-256: sha256=followed by the hex signature. - In production code, compare signatures with a constant-time function, such as
crypto.timingSafeEqualin Node.js, not==.
For a plain hash with no key, use the Hash Generator.