HMAC Generator Online | SHA-256, SHA-384, SHA-512 Message Authentication
Hash Functions How It Works
What Is HMAC?
HMAC (Hash-based Message Authentication Code) is a mechanism for verifying both the integrity and authenticity of a message using a cryptographic hash function and a shared secret key. Unlike a plain hash, only someone who knows the secret key can produce or verify the authentication tag. HMAC is used in API authentication, webhook verification (Stripe, GitHub, Slack), JWT tokens, and secure message exchange.
When to Use HMAC
- API request signing — authenticate requests by including an HMAC signature that only the client and server can verify
- Webhook verification — Stripe, GitHub, and Slack send HMAC signatures with webhook payloads to verify authenticity
- JWT tokens — HMAC-SHA256 (HS256) is the default algorithm for signing JSON Web Tokens
- Message authentication — verify that a message came from a trusted source and hasn't been tampered with
- Session verification — sign session tokens to detect tampering without storing server-side state
HMAC Algorithm Reference
| Algorithm | Output Size | Hex Length | Base64 Length | Best for |
|---|---|---|---|---|
| HMAC-SHA256 | 256-bit (32 bytes) | 64 chars | 44 chars | API authentication, JWT, webhooks |
| HMAC-SHA384 | 384-bit (48 bytes) | 96 chars | 64 chars | High-security applications |
| HMAC-SHA512 | 512-bit (64 bytes) | 128 chars | 88 chars | Maximum security margin |
Standards Compliance
- RFC 2104 — HMAC: Keyed-Hashing for Message Authentication
- RFC 4231 — Identifiers and Test Vectors for HMAC-SHA-224, HMAC-SHA-256, HMAC-SHA-384, and HMAC-SHA-512
- NIST FIPS 198-1 — The Keyed-Hash Message Authentication Code (HMAC)
- Web Crypto API — W3C standard for browser-native HMAC via
crypto.subtle.sign()
Last updated:
Code Examples
JavaScript (Browser — Web Crypto API)
// HMAC-SHA256
const key = await crypto.subtle.importKey(
'raw',
new TextEncoder().encode('secret-key'),
{ name: 'HMAC', hash: 'SHA-256' },
false,
['sign']
);
const message = new TextEncoder().encode('hello world');
const signature = await crypto.subtle.sign('HMAC', key, message);
const hmac = Array.from(new Uint8Array(signature))
.map(b => b.toString(16).padStart(2, '0')).join('');
console.log(hmac); Python
import hmac
import hashlib
key = b'secret-key'
message = b'hello world'
# HMAC-SHA256
signature = hmac.new(key, message, hashlib.sha256).hexdigest()
print(f'HMAC-SHA256: {signature}')
# HMAC-SHA512
signature_512 = hmac.new(key, message, hashlib.sha512).hexdigest()
print(f'HMAC-SHA512: {signature_512}') Go
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"fmt"
)
func main() {
key := []byte("secret-key")
message := []byte("hello world")
mac := hmac.New(sha256.New, key)
mac.Write(message)
signature := mac.Sum(nil)
fmt.Println("HMAC-SHA256:", hex.EncodeToString(signature))
} Rust
use hmac::{Hmac, Mac};
use sha2::Sha256;
type HmacSha256 = Hmac<Sha256>;
fn main() {
let key = b"secret-key";
let message = b"hello world";
let mut mac = HmacSha256::new_from_slice(key)
.expect("HMAC can take key of any size");
mac.update(message);
let result = mac.finalize();
println!("HMAC-SHA256: {:x}", result.into_bytes());
} Node.js
const crypto = require('crypto');
const key = 'secret-key';
const message = 'hello world';
const hmac = crypto.createHmac('sha256', key)
.update(message)
.digest('hex');
console.log('HMAC-SHA256:', hmac); Common Pitfalls
crypto.timingSafeEqual(). In Python, use hmac.compare_digest().
Security Notes
Disclaimer
This tool is provided for educational and development purposes. HMAC is a critical security mechanism — always follow RFC 2104 guidelines and consult a security professional for production deployments. All computation occurs entirely in your browser.
Further Reading
- RFC 2104 — HMAC: Keyed-Hashing for Message Authentication
- RFC 4231 — Identifiers and Test Vectors for HMAC-SHA-2
- NIST FIPS 198-1 — The Keyed-Hash Message Authentication Code
- Wikipedia — HMAC
Related Concepts
- HMAC Message Authentication — How It Works
- SHA Hash Generator — Plain Hashing Without a Key
- JWT Signer & Verifier — HMAC in JWT Tokens
- HMAC Generator
Related Tools
Need to generate a plain hash without a key? Try the SHA Hash Generator. For signing full JWT tokens with HMAC, see the JWT Signer & Verifier. You can also derive keys from passwords using the KDF Hash Generator.
Frequently Asked Questions
What is the difference between HMAC and a regular hash?
A regular hash (like SHA-256) only verifies data integrity — anyone can compute it. HMAC adds a secret key, so only someone who knows the key can produce or verify the authentication tag. This provides both integrity and authenticity.
When should I use HMAC?
HMAC is used when you need to verify that a message came from a trusted source and hasn't been tampered with. Common uses include API authentication (signing requests), JWT tokens, session verification, webhook signatures (Stripe, GitHub, Slack), and secure message exchange between parties.
Which HMAC algorithm should I use?
HMAC-SHA256 is the standard choice and what most APIs expect. HMAC-SHA384 and HMAC-SHA512 offer larger outputs for higher security margins. Avoid HMAC-SHA1 for new systems as SHA-1 is no longer considered secure.
What is the difference between hex and Base64 output?
Both encode the same HMAC bytes. Hex (lowercase) produces a 64-character string for SHA-256, while Base64 produces a 44-character string. Choose based on your integration requirements — GitHub webhooks use hex, while some other services prefer Base64.
How does HMAC verification work?
Verification recomputes the HMAC using the same message, key, and algorithm, then compares it to the expected signature using constant-time comparison to prevent timing attacks. If they match, the message is authentic and untampered.
Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.
More in Hash
SHA Hash Generator
Generate SHA-256 or SHA-512 hashes from text or files online. Real-time computation, batch upload with CSV export, Hex/Base64 output.
Hash Compare
Compute and compare SHA-1, SHA-256, SHA-384, and SHA-512 hashes side by side online. Hex/Base64 output for checksum verification.
Bcrypt Hash Generator
Generate and verify bcrypt password hashes online. Adjustable cost factor (4-20), real bcryptjs implementation, Node.js compatible.
Merkle Tree Generator
Build Merkle trees and generate proofs online. SHA-256, SHA-512, Keccak-256. Bitcoin duplicate & promote odd-leaf, OpenZeppelin sorted pairs.