Generate HMAC-SHA-256 from command line:
echo -n "message" | openssl dgst -sha256 -hmac "secret-key"
Using a key file:
openssl dgst -sha256 -hmac "$(cat keyfile)" -binary message.txt | base64
Enter a message, secret key, select algorithms, then click Compute HMAC
| Algorithm | Output Size | Status |
|---|---|---|
| HMAC-SHA-256 | 256 bits (32 bytes) | Recommended |
| HMAC-SHA-512 | 512 bits (64 bytes) | Recommended |
| HMAC-SHA-1 | 160 bits (20 bytes) | Legacy |
| HMAC-MD5 | 128 bits (16 bytes) | Weak |
| HMAC-RIPEMD-160 | 160 bits (20 bytes) | Niche |
HMAC (Hash-based Message Authentication Code) is a construction that combines a cryptographic hash function with a secret key. It provides two properties:
The HMAC formula: HMAC(K, m) = H((K ⊕ opad) || H((K ⊕ ipad) || m))
A plain hash like SHA-256(message) only detects accidental changes. Anyone can recompute it. HMAC adds a secret key so only authorized parties can generate or verify the MAC.
Python
import hmac
import hashlib
key = b'secret-key'
message = b'Hello, World!'
signature = hmac.new(key, message, hashlib.sha256).hexdigest()
print(signature)
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);
Every coffee helps keep the servers running. Every book sale funds the next tool I'm dreaming up. You're not just supporting a site — you're helping me build what developers actually need.