Hmac generator
What is a Hmac Generator?
An HMAC (Hash-based Message Authentication Code) combines a secret key with a hash function to create a signature for a message. Anyone who knows the key can recompute it to confirm that the message was not changed and came from someone holding the key. HMAC is used to sign webhooks, API requests, JWTs (HS256) and cookies.
How to use it
- Enter the message, for example a webhook body.
- Enter the secret key.
- Choose the hash algorithm, usually SHA-256.
- Copy the HMAC in hex or Base64 and compare it with the expected signature.
Example
HMAC-SHA256 of the message The quick brown fox jumps over the lazy dog with the key key is f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8.
Verifying webhooks
Services such as Stripe, GitHub, Shopify and Razorpay send a signature header with each webhook. To verify it:
- Use the raw request body, exactly as received. Parsing and re-serialising JSON changes spacing and breaks the signature.
- Include any extra data the provider specifies, such as Stripe's timestamp prefix.
- Compare signatures with a constant-time function to avoid timing attacks.
- Reject old timestamps to prevent replay attacks.
Why not just hash the key and message together?
Naive constructions like SHA256(key + message) are vulnerable to length-extension attacks. HMAC's nested design avoids this, even with SHA-256.
Calculations run locally; your secret key never leaves the browser.
Frequently Asked Questions
What is HMAC used for?
To verify that a message has not been altered and was created by someone holding the shared secret key, for example in webhooks and API signing.
Why does my webhook signature not match?
Most often because the body was parsed and re-serialised. Use the exact raw bytes received, and check the key and encoding.
Should the HMAC be hex or Base64?
Either, depending on the provider. GitHub uses hex, while some providers use Base64. Match their documentation.
Is HMAC the same as encryption?
No. HMAC proves integrity and authenticity, but the message itself remains readable.