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.
Related Developer Tools
Chain HMAC Signature Generator with these complementary client-side utilities from our Developer Tools collection:
Encode special characters into standard HTML entities or decode escaped symbols back to plain text. 100% private, client-side browser converter.
Write Markdown text and preview formatted HTML output in real-time. Features split-screen editing, copy compiled HTML, and offline browser processing.
Format, beautify, minify, and validate JSON data. Find syntax errors and pretty print JSON in your browser locally.
Convert JSON to YAML and YAML to JSON online instantly. 100% private, browser-based bidirectional converter with syntax checking.
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.