HMAC Generator & Verifier
Generate and validate RFC 2104 Hash-based Message Authentication Codes (HMAC-SHA256, HMAC-SHA512, HMAC-SHA1, and HMAC-MD5) locally for text payloads and files using Web Crypto APIs.
Message: "Hello World" Secret Key: "my-secret-key" Algorithm: HMAC-SHA256Ready locally via WebAssembly & JavaScript
d070b471207e997486f059bc422998a69e7f45b7410214a1a72097e3a1f8021d100% Client-Side • Zero Server Upload
Unkeyed checksums such as raw SHA-256 catch accidental bit corruption, yet anyone who intercepts a message can alter the payload and recompute a fresh digest to match. HMAC (Hash-based Message Authentication Code), standardized in RFC 2104 and FIPS 198-1, solves both data integrity and origin authentication simultaneously by binding the digest calculation to a shared cryptographic secret key. Without that secret, an attacker cannot forge a valid authentication tag for a modified HTTP webhook, API request, or signed cookie—making HMAC the backbone of Stripe, GitHub, Shopify, Slack, AWS Signature Version 4, and symmetric JWT (HS256/HS512) authentication.
RFC 2104 Nested Hashing and Length-Extension Defense
Developers occasionally attempt to roll a lightweight signature scheme using SHA-256(secret || message). On Merkle–Damgård hash functions (MD5, SHA-1, SHA-256, SHA-512), that naive pattern is fatally vulnerable to length-extension attacks: because the final digest directly exposes the hash function's internal chaining state, an adversary can resume compression from that digest, append forged parameters (such as &role=admin), and generate a valid hash without ever learning secret.
RFC 2104 defeats length extension through a two-pass nested construction using fixed padding constants ipad (0x36 repeated B times) and opad (0x5c repeated B times), where B is the underlying hash function's internal block size in bytes:
HMAC(K, m) = H( (K' XOR opad) || H( (K' XOR ipad) || m ) )
Before XORing, RFC 2104 normalizes the secret key K to exact length B bytes to derive K':
- If
len(K) > B, the key is first compressed viaK' = H(K)and then right-padded with0x00bytes to lengthB. - If
len(K) < B, the key is right-padded directly with0x00bytes to lengthB. - If
len(K) == B,K' = Kdirectly.
Because the inner hash output is immediately wrapped inside a second keyed outer hash pass, an attacker never observes the internal state corresponding to the message boundary. Even more remarkably, HMAC's security proof relies on the pseudorandomness (PRF) of the underlying compression function rather than strict collision resistance—which is why HMAC-SHA1 and even HMAC-MD5 have not suffered practical key-recovery breaks despite raw MD5 and SHA-1 collisions, though new systems should still standardize exclusively on HMAC-SHA256 or HMAC-SHA512.
HMAC Variant Specifications and Key Entropy Guidelines
Selecting the right HMAC algorithm depends on protocol interoperability, compliance requirements, and CPU architecture. Notice how HMAC-SHA512 doubles the internal block size to 128 bytes, which affects both key normalization boundaries and throughput on 64-bit servers.
| Algorithm | Tag Size | Hex Chars | Block Size (B) | Min Recommended Key (NIST SP 800-107) | Security Status | Common Real-World Deployments |
|---|---|---|---|---|---|---|
| HMAC-SHA256 | 256 bits | 64 | 64 bytes | 32 bytes (256 bits) | Recommended Default | GitHub X-Hub-Signature-256, Stripe, Shopify, AWS SigV4, JWT HS256 |
| HMAC-SHA512 | 512 bits | 128 | 128 bytes | 64 bytes (512 bits) | High Assurance | JWT HS512, Kraken/exchange API signing, high-security internal RPCs |
| HMAC-SHA1 | 160 bits | 40 | 64 bytes | 20 bytes (160 bits) | Legacy Compatibility | OAuth 1.0a, RFC 6238 TOTP / RFC 4226 HOTP, older webhook providers |
| HMAC-MD5 | 128 bits | 32 | 64 bytes | 16 bytes (128 bits) | Deprecated / Legacy | Legacy CRAM-MD5 mail auth and retired enterprise SOAP endpoints |
For new webhook secrets and API signing keys, generate at least 32 random bytes from a CSPRNG—either via this tool's built-in window.crypto.getRandomValues() key generator or a dedicated Random String Generator.
Production Webhook and API Request Verification Patterns
This tool signs text payloads and files up to 20 MB with the browser's native window.crypto.subtle.importKey and crypto.subtle.sign APIs (falling back to 2 MB chunked streaming for larger files and HMAC-MD5), keeping sensitive signing keys strictly off remote servers. When moving from local debugging into backend production code, enforce two non-negotiable rules: sign the raw unparsed request buffer and compare signatures in constant time to prevent timing side-channel attacks.
// Node.js (Express / Next.js Route Handler) constant-time webhook check
import crypto from 'node:crypto';
export function verifyWebhookSignature(rawBodyBuffer, secret, headerHex) {
const expected = crypto
.createHmac('sha256', secret)
.update(rawBodyBuffer)
.digest();
const received = Buffer.from(headerHex.replace(/^sha256=/i, '').trim(), 'hex');
if (expected.length !== received.length) return false;
return crypto.timingSafeEqual(expected, received);
}
# Python standard library constant-time HMAC-SHA256 verification
import hashlib, hmac
def verify_signature(raw_body: bytes, secret: str, header_hex: str) -> bool:
expected = hmac.new(secret.encode("utf-8"), raw_body, hashlib.sha256).hexdigest()
cleaned = header_hex.removeprefix("sha256=").strip().lower()
return hmac.compare_digest(expected, cleaned)
Debugging Signature Mismatches in Real-World Integrations
When a webhook verification fails despite matching algorithms and keys, inspect these four high-frequency integration bugs:
- JSON Body Re-Serialization: Middleware like
express.json()parses and discards whitespace. PassingJSON.stringify(req.body)into HMAC alters key ordering, whitespace, or Unicode escapes (\/vs/), breaking the signature. Always capture the rawBufferbefore JSON parsing. - Header Format & Base64 vs. Hex Encoding: GitHub prepends
sha256=to a lowercase hex tag, Stripe packs a timestamp and signature intot=1700000000,v1=<hex>(signing${timestamp}.${rawBody}to stop replay attacks), while Shopify transmits a Base64-encoded binary HMAC digest rather than hex. When debugging signed JSON Web Tokens (HS256/HS512) alongside HMAC signatures, inspect the decoded Base64url header and claims with our JWT Decoder. - Hex-String vs. Raw-Byte Secret Keys: Confirm whether the provider treats a 64-character hex secret as 64 UTF-8 ASCII bytes (standard for most webhook dashboards) or decodes it into 32 raw binary bytes before passing it into HMAC.
- Canonical Header & Query Ordering: Protocol schemes such as AWS Signature Version 4 require strict alphabetical query sorting, lowercase header trimming, and specific
\nline feeds in the canonical request string before applying chained HMAC-SHA256 derivation keys.
How to Use HMAC Generator & Verifier
Select your target algorithm (HMAC-SHA256, HMAC-SHA512, HMAC-SHA1, or HMAC-MD5) from the algorithm bar.
Enter your shared secret key, or click the CSPRNG generator button to produce a random 32-byte hex key.
Paste the raw message payload under 'Text Input' or switch to 'File Hash' to sign a local binary file.
Inspect the generated hexadecimal authentication tag and toggle uppercase formatting or auto-copy as needed.
Paste an expected webhook or API header digest into the verification field to confirm cryptographic validity.
Real Examples
HMAC-SHA256 Text Signature
Standard HMAC signature using SHA256 with a simple text payload and secret key.
Message: "Hello World"
Secret Key: "my-secret-key"
Algorithm: HMAC-SHA256d070b471207e997486f059bc422998a69e7f45b7410214a1a72097e3a1f8021dHMAC-SHA512 Secure Sign
HMAC signature using SHA512 showing high output entropy for military-grade protection.
Message: "Secure Payload"
Secret Key: "highly-secure-token"
Algorithm: HMAC-SHA512eb71b10a2cd92d9d15c1e5ad7448e65839958cf0b784a929fa3a2be10d8fa0fb776cf5c6bf1bcfc23e85e50587de5b441f7b8893699c6934cfa7350f55cf55ceWebhook Signature Simulation
Calculating the HMAC-SHA256 of a JSON payload representing a Stripe-style webhook.
Message: "{"id":"evt_123","type":"charge.succeeded"}"
Secret Key: "whsec_key"
Algorithm: HMAC-SHA25649e5d4de768ccb130a08a28ccb673df64bdf9f52f7f98be1f60037a1c2cbdf48Frequently Asked Questions
Why is HMAC safer than hashing a concatenated secret and message like SHA256(secret + payload)?
Does this HMAC generator send my secret keys or webhook payloads to a server?
How long should my HMAC secret key be?
Why did my webhook HMAC verification fail in Express, Next.js, or Fastify?
Why must server-side HMAC verification use constant-time comparison?
Key Features
- RFC 2104 signing and verification across HMAC-SHA256, HMAC-SHA512, HMAC-SHA1, and HMAC-MD5
- Native Web Crypto API (SubtleCrypto) execution with automatic 2 MB chunked streaming for files over 20 MB
- Built-in CSPRNG secret key generator powered by window.crypto.getRandomValues() for 256-bit keys
- Instant signature comparison box to validate incoming webhook headers and API authentication tokens
- Masked secret-key visibility toggle, uppercase/lowercase hex switch, auto-copy mode, and shareable test links
- Built-in developer code snippets for webhook handlers, AWS signing, JWT HS256, and Express verification
Common Use Cases
- Debugging and verifying incoming webhook signatures from Stripe, GitHub, Shopify, Slack, and Twilio
- Signing canonical REST API requests, query strings, and AWS Signature Version 4 authorization headers
- Validating symmetric JSON Web Token (JWT) HS256 and HS512 signatures during authentication troubleshooting
- Generating authenticated tamper-evident tags for local archive files and cross-service message queues
- Creating high-entropy 256-bit symmetric signing secrets locally with the browser's CSPRNG
- Testing edge cases in legacy HMAC-SHA1 (OAuth 1.0a / TOTP RFC 6238) or HMAC-MD5 integrations
Related Tools
Explore More Tools in This Category
View All Developer & Utility ToolsQR Code Generator & Designer
Create permanent, non-expiring QR codes for URLs, WiFi networks, vCards, events, and crypto addresses with custom colors, gradients, rounded modules, embedded logos, and instant SVG, PNG, or batch ZIP downloads.
Linux Chmod Permissions Calculator
Compute exact Unix octal bitmasks and symbolic permission strings for Owner, Group, and Others with real-time bitwise evaluation.
Base64 Encoder — Text, File & Data URI Encoding Tool
Encode and decode UTF-8 text, JSON payloads, images, and binary files using RFC 4648 standard or URL-safe Base64url with instant Data URI output and live byte-expansion metrics, 100% client-side.
Base64 Decode Tool
Decode standard RFC 4648 and URL-safe Base64 strings into readable UTF-8 text, formatted JSON, or downloadable images with automatic magic-byte sniffing directly inside your browser.
URL Encoder & Decoder Tool
Percent-encode full URIs, individual query parameters, and multi-byte UTF-8 text using RFC 3986 and JavaScript encodeURI/encodeURIComponent rules with an interactive query string builder.
URL Decoder Tool
Unescape percent-encoded URLs and query strings back into readable UTF-8 text, inspect and edit key-value parameters visually, and diagnose malformed or double-encoded sequences locally in your browser.
JWT Decoder Tool
Inspect JSON Web Tokens locally in real time. Decode Base64url headers and payload claims, evaluate Unix exp/iat/nbf timelines, and flag risky signing algorithms without sending tokens over the network.
Hash Generator Tool
Compute MD5, SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA3-256, and SHA3-512 cryptographic digests simultaneously for text or local files directly inside your browser.