HMAC Signature Generator
Compute Hash-based Message Authentication Codes (HMAC) using SHA-256 or SHA-512 securely on the client-side.
RFC 2104 Hash-based Message Authentication Codes (HMAC)
A Hash-based Message Authentication Code (HMAC) is a specific type of cryptographic message authentication code specified by RFC 2104 and FIPS PUB 198-1. HMAC combines a cryptographic hash function (such as SHA-256, SHA-384, or SHA-512) with a shared secret key to simultaneously verify both the data integrity and the authenticity of a message.
HMAC is the foundational protocol used in modern API security architectures, webhook signature verifications (Stripe, GitHub, Shopify, PayPal), AWS Signature Version 4 signing, and JWT creation. Unlike naive hash combinations like hash(key + message) which are catastrophically vulnerable to length extension attacks, HMAC employs a rigorous two-pass nested hashing algorithm utilizing inner padding (ipad) and outer padding (opad) constants.
Our HMAC Generator utilizes the W3C Web Cryptography API (window.crypto.subtle) natively inside your browser, producing true cryptographic signatures in Hexadecimal and Base64 formats without sending secret keys across the network.
HMAC-SHA256 Code Examples in JavaScript, Python & CLI
Implement HMAC verification in your backend webhooks using these production snippets:
// Node.js using crypto module
import crypto from 'crypto';
const secretKey = "super-secret-key";
const message = "payload-data-to-sign";
const signatureHex = crypto
.createHmac('sha256', secretKey)
.update(message)
.digest('hex');
console.log("HMAC-SHA256 (Hex):", signatureHex);
# Python 3
import hmac, hashlib
secret = b"super-secret-key"
payload = b"payload-data-to-sign"
signature = hmac.new(secret, payload, hashlib.sha256).hexdigest()
print(f"HMAC-SHA256: {signature}")
# Bash CLI using openssl
echo -n "payload-data-to-sign" | openssl dgst -sha256 -hmac "super-secret-key"
Preventing Timing Attacks with Constant-Time Comparison
When validating incoming HMAC webhook signatures on a web server, never compare strings using standard equality operators (like if (receivedSig === expectedSig)). Standard string comparisons terminate early on the first mismatched byte, allowing attackers to measure microscopic response time differences and reconstruct secret keys byte-by-byte (timing attack).
Always enforce constant-time comparisons using crypto.timingSafeEqual() in Node.js or hmac.compare_digest() in Python.
Selecting the Right Digest Algorithm: SHA-256 vs SHA-512
While HMAC-MD5 and HMAC-SHA1 remain defined in legacy standards, they are considered cryptographically obsolete and deprecated. For all modern systems, HMAC-SHA256 is the global industry standard, providing 128 bits of security strength against collision and preimage attacks. For top-secret or high-security banking infrastructure, HMAC-SHA512 provides maximum cryptographic margin.
FIPS 198-1 Keyed-Hashing & Timing Attack Mitigation
Hash-based Message Authentication Codes (HMAC), standardized under RFC 2104 and FIPS PUB 198-1, combine a cryptographic hash function (SHA-256, SHA-512) with a secret key to verify both data integrity and the authentic identity of the message sender. HMAC eliminates length-extension vulnerabilities present in naive concatenation schemes like hash(key + message).
HMAC functions through an inner and outer hashing pass utilizing two fixed constants: the inner padding ipad (0x36 repeated) and outer padding opad (0x5c repeated). When verifying HMAC digests in webhooks (Stripe, GitHub, Shopify), developers must use constant-time equality comparisons (e.g. crypto.timingSafeEqual()) to prevent side-channel timing attacks that deduce secret keys byte by byte.
Web Crypto API Implementation Details
Our tool leverages the native window.crypto.subtle.sign() API. The secret key is imported as an unextractable CryptoKey object and processed directly in browser memory, guaranteeing that keys are never logged or stored.
Webhook Signature Verification & Preventing Replay Attacks
In modern SaaS webhooks (such as Stripe, GitHub, and Slack), HMAC digests are transmitted alongside an epoch timestamp header (e.g. Stripe-Signature: t=1700000000,v1=...). To prevent replay attacks—where an eavesdropper intercepts a valid payload and re-transmits it—the recipient server concatenates the timestamp with the request body before computing the HMAC, rejecting any request where the timestamp deviates by more than 5 minutes.
Frequently Asked Questions
Because HMAC uses a nested hash structure H(K XOR opad || H(K XOR ipad || m)), the internal hash state is never exposed directly in the final output, completely neutralizing length extension attacks.
HMAC relies on symmetric cryptography (both parties must know the same secret key). Digital signatures (like RSA or ECDSA) rely on asymmetric key pairs (private key signs, public key verifies).
Yes. You can input keys as UTF-8 plaintext strings or raw hexadecimal byte representations.
No. Cryptographic hashes are one-way mathematical functions. HMAC generates an irreversible authentication tag; it is not an encryption mechanism.
Never. All cryptographic computations are executed in your browser via window.crypto.subtle. Your secret keys never leave your machine.