Skip to content
BetterPass logo

HMAC Generator — Hash-based Message Authentication Codes

Hash or verify HMAC tags — with webhook signature presets for Stripe, GitHub, and Slack. Runs entirely in your browser.

Result

Your input never leaves your device; HMAC is computed locally using the Web Crypto API.

What is HMAC Generator?

HMAC (Hash-based Message Authentication Code) combines a cryptographic hash function with a secret key to create a message authentication code. It verifies both the integrity and authenticity of a message. HMAC is the "H" in HS256 — sign and verify JWTs with our JWT tool.

Integrity + Authenticity — unlike a plain hash, HMAC proves the message hasn't been altered AND was created by someone who knows the secret key.
Standardized in RFC 2104 — used in TLS, JWT (HS256/HS512), IPsec, and many API authentication schemes.
Webhook signing — Stripe (t=…,v1=…), GitHub (sha256=…) and Slack (v0=…) all sign their webhook payloads with HMAC-SHA-256. This tool can build and verify those headers.
Keyed hash — the security depends on keeping the secret key private; the hash algorithm alone doesn't provide authenticity.
Parallel-safe — each (message, key) pair produces a unique tag; no chaining or state between computations.

Zero-Server Tool Data Guarantee

All computation happens locally in your browser using the Web Crypto API. Your message and secret key are never sent to any server.

How to Use

01

Enter Message

Type or paste the message (or webhook payload) you want to authenticate.

02

Enter Secret Key

Provide a secret key that is shared between the sender and receiver.

03

Select Algorithm or Preset

Choose SHA-256/SHA-512, or pick a Stripe, GitHub, or Slack preset to build the exact signature header those services expect.

04

Copy the HMAC

The HMAC is computed instantly. Use the copy button to save the hex string or the full webhook header.

Common Use Cases

API Request Signing

Sign each API request with HMAC so the server can verify it wasn't modified in transit and came from a trusted client.

Webhook Verification

Many services (Stripe, GitHub, Slack) send HMAC signatures with webhooks. Verify them to ensure requests are authentic.

JWT (HS256/HS512)

HMAC is the 'H' in HS256 — it's used to sign JWTs when you want symmetric (shared-secret) authentication.

Data Integrity

Append an HMAC tag to sensitive data (like cookies or URLs) and verify it before processing to detect tampering.

Implementation Examples

JavaScriptBrowser (Web Crypto API)
async function hmacSign(message, secret, algo = 'SHA-256') {
const enc = new TextEncoder();
const key = await crypto.subtle.importKey(
'raw', enc.encode(secret),
{ name: 'HMAC', hash: algo }, false, ['sign']
);
const sig = await crypto.subtle.sign('HMAC', key, enc.encode(message));
return Array.from(new Uint8Array(sig))
.map(b => b.toString(16).padStart(2, '0')).join('');
}
const mac = await hmacSign('hello', 'my-secret-key');
// "c0e5d7337d0470a..."

HMAC vs Plain Hash vs Digital Signature

FeatureHMACPlain Hash (SHA-256)Digital Signature (RSA/ECDSA)
Provides integrity?YesYesYes
Provides authenticity?Yes (shared key)NoYes (public key)
Key typeSymmetric (shared)NoneAsymmetric (public/private)
PerformanceFastFastestSlow (especially RSA)
Use caseAPI auth, webhooksChecksums, dedupCode signing, certificates
Non-repudiation?No (both parties have key)NoYes

Production Best Practices & Security

Use HMAC-SHA-256 or HMAC-SHA-512 — avoid HMAC-SHA-1 for new designs, though it's still widely used in legacy systems. Why:SHA-256 and SHA-512 provide significantly higher security margins and are resistant to collision attacks (two different inputs producing the same hash) that affect older algorithms.
Keep the secret key truly secret — never hardcode keys in source code or client-side JavaScript; use environment variables or a secrets manager. Why:If an attacker finds your secret key, they can generate valid HMACs for any message, completely bypassing your integrity and authenticity checks.
Use a unique key per context — don't share the same HMAC key across different services or purposes. Why:Key reuse across different systems increases the risk; a compromise in one service would compromise all services sharing that key.
Verify HMAC on every request — don't skip verification even if you trust the network; network-level attacks can modify messages in transit. Why:Even within a "trusted" network, man-in-the-middle attacks can still occur. HMAC ensures that data remains authentic throughout its journey.
Use constant-time comparison — always compare HMACs with a timing-safe function to prevent timing side-channel attacks. Why:Standard string comparisons stop at the first differing character, allowing attackers to measure processing time and guess the HMAC character by character.
Rotate keys periodically — implement key rotation with a key ID to seamlessly switch between old and new keys. Why:Rotation limits the damage if a key is ever leaked, as the stolen key will only be valid for a limited window.

Frequently Asked Questions

HMAC (Hash-based Message Authentication Code) is a keyed-hash construct defined in RFC 2104 and FIPS 198-1. It uses a cryptographic hash function (like SHA-256) combined with a secret key to produce a fixed-length authentication tag.

Unlike a plain hash — which anyone can compute — HMAC ensures that only parties who possess the shared secret key can generate or verify the tag.

This makes HMAC essential for API authentication (where the server verifies requests come from an authorized client), JWT signatures (HS256), and any scenario requiring both message integrity and origin authenticity.