splitforms.com
Free tool · runs in your browser

HMAC-SHA256 Generator & Webhook Signature Verifier

Calculate an HMAC from a secret and a message, or check the signature a webhook sent you. Presets match how GitHub, Stripe, Shopify, Slack and splitforms sign their requests. Nothing you type is sent to a server.

Verify a signature

Paste the signature header you received. A sha256= or v0= prefix is stripped, and the v1= value is read from a full Stripe-Signature header. The check uses the secret, body, timestamp, algorithm and output encoding on the left.

The bytes are compared in constant time. Your secret and body never leave this page: the HMAC is calculated by your browser's Web Crypto API and nothing is sent to a server.

What is HMAC?

HMAC (hash-based message authentication code) mixes a shared secret into a hash of the message. Only someone with the secret can produce the right value, and changing a single byte of the message changes the whole result. Webhook senders put the HMAC of the request body in a header; the receiver calculates it again over the raw body with the same secret and compares the two.

Try GitHub's documented test vector: secret It's a Secret to Everybody and body Hello, World! with the GitHub preset give sha256=757107ea0eb2509fc211221cce984b8a37570b6d7586c22c46f4379c8b043e17.

HMAC verification code

Verify on the server with the raw request body and a timing-safe compare. Both snippets check a sha256=<hex> header like GitHub's and splitforms'.

Node.js: createHmac and timingSafeEqual

verify-signature.mjs

import { createHmac, timingSafeEqual } from "node:crypto";

// rawBody: the exact request bytes (a Buffer), not re-serialized JSON.
// header: e.g. req.headers["x-hub-signature-256"] = "sha256=<hex>"
export function verifySignature(rawBody, header, secret) {
  const received = Buffer.from(String(header).replace(/^sha256=/, ""), "hex");
  const expected = createHmac("sha256", secret).update(rawBody).digest();
  return received.length === expected.length && timingSafeEqual(received, expected);
}

Python: hmac.compare_digest

verify_signature.py

import hashlib
import hmac

# raw_body: the exact request bytes, not re-serialized JSON.
# header: e.g. request.headers["X-Hub-Signature-256"] = "sha256=<hex>"
def verify_signature(raw_body: bytes, header: str, secret: str) -> bool:
    received = header.removeprefix("sha256=")
    expected = hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(received, expected)

For Stripe, Shopify and Slack code, see how to verify webhook signatures with HMAC.

HMAC and webhook signature FAQ

Why verify against the raw body and not re-serialized JSON?

The sender signs the exact bytes it sent. Parsing the JSON and calling JSON.stringify again can change whitespace, key order, number formatting or Unicode escaping, and any one changed byte gives a different HMAC. Read the raw request body first, verify it, then parse it.

Hex or base64: which output should I use?

Use whatever the provider's header carries. GitHub, Stripe, Slack and splitforms send hex; Shopify sends base64. Both encode the same digest bytes, so a SHA-256 HMAC is 64 hex characters or 44 base64 characters.

Why use a timing-safe compare?

A normal string compare stops at the first different character, so response times can leak how much of a guessed signature was right. Compare the bytes in constant time with crypto.timingSafeEqual in Node or hmac.compare_digest in Python. This page compares the bytes in constant time too.

How do timestamps protect against replay attacks?

An HMAC proves who sent a request, not when. Stripe and Slack sign a timestamp together with the body, so you can reject requests older than a few minutes (both suggest 5) and an attacker can't change the timestamp without breaking the signature. Where no timestamp is signed, deduplicate on an event or submission ID.

Is my secret sent anywhere?

No. The HMAC is calculated in your browser with the Web Crypto API (crypto.subtle). The secret, body and signature stay on this page and nothing is stored.

Related

Free form tools

Related tools.

Browse all 40 free tools

See the tools page →