About this tool
HMAC (Hash-based Message Authentication Code) combines a secret key with a hash function such as SHA-256. The result is a signature that proves two things: the message came from someone who knows the key, and it wasn’t changed on the way. Razorpay, Stripe, GitHub, Shopify, Slack and most other webhook providers sign their payloads this way, and many APIs use HMAC to sign requests.
How to use this HMAC generator
- Paste the message: the exact text that was signed, such as a webhook’s raw request body.
- Enter the secret key and pick its format. Most providers give you a plain string (choose Text). Pick hex or base64 only if the key itself is encoded that way.
- Choose the algorithm (HMAC-SHA256 is the usual choice) and the output format your provider uses: hex or Base64.
- Optionally paste the signature you received into Expected signature. It’s compared live, in hex or Base64, and prefixes like
sha256=or a whole Stripet=…,v1=…header are understood.
HMAC vs. a plain SHA-256 hash
A SHA-256 hash has no key: anyone can compute it, so it only detects accidental changes. An HMAC needs the secret key, so an attacker who changes the message can’t produce a valid signature. Don’t build your own “hash of secret + message”: plain SHA-256 is open to length-extension attacks, which HMAC’s construction prevents.
What each webhook provider signs
| Provider | Message to sign | Algorithm and output | Header |
|---|---|---|---|
| Razorpay | Raw body | HMAC-SHA256, hex | X-Razorpay-Signature |
| GitHub | Raw body | HMAC-SHA256, hex, sha256= prefix | X-Hub-Signature-256 |
| Stripe | timestamp.body | HMAC-SHA256, hex, in v1= | Stripe-Signature |
| Shopify | Raw body | HMAC-SHA256, Base64 | X-Shopify-Hmac-Sha256 |
| Slack | v0:timestamp:body | HMAC-SHA256, hex, v0= prefix | X-Slack-Signature |
| Twilio | Full URL + sorted POST params | HMAC-SHA1, Base64 | X-Twilio-Signature |
For Stripe, take the t= value from the header and sign t + "." + body. For Slack, the timestamp is in X-Slack-Request-Timestamp. You can capture a real request with its headers using the webhook tester.
Debug a webhook signature that doesn’t match
- Use the raw body. Parsing JSON and serialising it again changes spacing and key order, so the bytes and the signature change. Sign exactly what you received.
- Check the key format. A Stripe secret like
whsec_…is used as plain text, including the prefix. Some providers give a Base64 secret that must be decoded first. - Match the signed content. Some providers sign a timestamp plus the body, not the body alone (see the table above).
- Compare the right encoding. Hex and Base64 of the same signature look completely different. This tool checks both.
- Test vs. live secrets. Test-mode events are signed with the test-mode secret.
Generate HMAC-SHA256 in code
Each example produces the same result as this tool for the same message and key, in hex and in Base64.
const crypto = require('node:crypto');
const hex = crypto.createHmac('sha256', secret).update(message).digest('hex');
const b64 = crypto.createHmac('sha256', secret).update(message).digest('base64');
// Compare signatures in constant time
const ok = hex.length === received.length &&
crypto.timingSafeEqual(Buffer.from(hex), Buffer.from(received));import base64, hashlib, hmac
digest = hmac.new(secret.encode(), message.encode(), hashlib.sha256)
hex_sig = digest.hexdigest()
b64_sig = base64.b64encode(digest.digest()).decode()
ok = hmac.compare_digest(hex_sig, received) # constant-time compare<?php
$hex = hash_hmac('sha256', $message, $secret);
$b64 = base64_encode(hash_hmac('sha256', $message, $secret, true));
$ok = hash_equals($hex, $received); // constant-time compareimport javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HexFormat;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
byte[] sig = mac.doFinal(message.getBytes(StandardCharsets.UTF_8));
String hex = HexFormat.of().formatHex(sig); // Java 17+
String b64 = Base64.getEncoder().encodeToString(sig);import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
)
mac := hmac.New(sha256.New, []byte(secret))
mac.Write([]byte(message))
sig := mac.Sum(nil)
hexSig := hex.EncodeToString(sig)
b64Sig := base64.StdEncoding.EncodeToString(sig)
ok := hmac.Equal([]byte(hexSig), []byte(received)) // constant-time compare# hex
printf '%s' "$MESSAGE" | openssl dgst -sha256 -hmac "$SECRET" | awk '{print $NF}'
# base64
printf '%s' "$MESSAGE" | openssl dgst -sha256 -hmac "$SECRET" -binary | base64When you verify a signature, use a constant-time comparison (as in the examples). A normal string comparison can leak, through timing, how many leading characters were correct.
Choosing a secret key
Use a random key at least as long as the hash output: 32 bytes for HMAC-SHA256, 64 bytes for HMAC-SHA512. Keys longer than the hash’s block size (64 bytes for SHA-256) are hashed first, so extra length beyond that adds nothing. The webhook secret generator makes suitable keys.
FAQ
What is an HMAC generator used for?
To compute or check message signatures: debugging webhook signature verification, signing API requests, or checking that your own code produces the same HMAC as a provider.
What is the difference between HMAC and SHA-256?
SHA-256 is a hash with no key, so anyone can compute it. HMAC-SHA256 mixes a secret key into SHA-256, so only someone with the key can produce or check the signature.
Why doesn’t my signature match the provider’s?
Check four things: you are signing the exact raw body (no re-formatting), the key format (text vs. base64/hex) is right, you are signing the same content (some providers sign "timestamp.body"), and you are comparing the same encoding (hex vs. Base64).
Should I use hex or Base64 output?
Use whatever your provider or API expects. Razorpay, GitHub, Stripe and Slack use hex. Shopify and Twilio use Base64. Both encode the same signature bytes.
How long should an HMAC key be?
At least as long as the hash output: 32 random bytes for HMAC-SHA256 and 64 for HMAC-SHA512. Shorter keys are weaker; longer keys than the block size give no extra security.
Can an HMAC be decrypted or reversed?
No. HMAC is a one-way function. You can only recompute it with the same key and message and compare the results.
Is HMAC-SHA1 still safe?
HMAC-SHA1 is not broken the way plain SHA-1 collisions are, and some services such as Twilio still use it. Prefer HMAC-SHA256 for anything new.
Are my key and message sent anywhere?
No. The HMAC is computed in your browser with crypto.subtle.sign(). Nothing is uploaded.