Hash Generator (MD5, SHA-256)Specialized Version
#️⃣

HMAC Generator

Generate HMAC signatures

128 bits (32 hex characters)
160 bits (40 hex characters)
256 bits (64 hex characters)
512 bits (128 hex characters)
Security Note: Never use MD5 or SHA-1 for passwords or security-critical applications. For password hashing, use specialized algorithms like bcrypt, scrypt, or Argon2. These hash functions are suitable for checksums and data integrity verification.

HMAC Generator

Generate HMAC (Hash-based Message Authentication Code) signatures for API authentication and message integrity verification. HMAC combines a cryptographic hash with a secret key to create unforgeable signatures.

Understanding HMAC

PropertyDescription
PurposeMessage authentication
ComponentsMessage + Secret key + Hash
OutputFixed-size signature
SecurityProves message origin & integrity

HMAC vs Plain Hashing

FeaturePlain HashHMAC
Uses secret keyNoYes
Verifies senderNoYes
Prevents tamperingDetectsDetects + authenticates
API securityInsufficientRecommended

HMAC Implementation

``javascript // Node.js const crypto = require('crypto');

function generateHmac(message, secret, algorithm = 'sha256') { return crypto .createHmac(algorithm, secret) .update(message) .digest('hex'); }

// Example const signature = generateHmac('Hello World', 'my-secret-key'); // "a1b2c3d4e5f6..."

// Verify HMAC function verifyHmac(message, secret, signature) { const expected = generateHmac(message, secret); return crypto.timingSafeEqual( Buffer.from(signature), Buffer.from(expected) ); } `

Web Crypto API (Browser)

`javascript async function generateHmacBrowser(message, secret) { const encoder = new TextEncoder(); const key = await crypto.subtle.importKey( 'raw', encoder.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'] );

const signature = await crypto.subtle.sign( 'HMAC', key, encoder.encode(message) );

return Array.from(new Uint8Array(signature)) .map(b => b.toString(16).padStart(2, '0')) .join(''); } `

API Request Signing

`javascript // Sign an API request function signRequest(method, path, body, timestamp, secret) { const message = ${method}\n${path}\n${timestamp}\n${body}; return generateHmac(message, secret); }

// Example const signature = signRequest( 'POST', '/api/orders', JSON.stringify({ item: 'book', qty: 1 }), Date.now().toString(), 'api-secret-key' ); ``

Common HMAC Algorithms

AlgorithmSecurityUse Case
HMAC-MD5WeakLegacy only
HMAC-SHA1AcceptableOAuth 1.0
HMAC-SHA256StrongAWS, Stripe, most APIs
HMAC-SHA512Very strongHigh-security needs

Frequently Asked Questions

What is HMAC used for?

HMAC is used for message authentication—proving that a message came from someone with the secret key and wasn't modified in transit. Common uses include API request signing (AWS, Stripe), webhook verification, session tokens, and any scenario where you need to verify both integrity and authenticity of data.

Why use HMAC instead of just hashing?

Plain hashes can be computed by anyone with the data. HMAC requires both the data AND the secret key, proving the sender knows the secret. This prevents attackers from forging signatures or modifying messages. HMAC also protects against length extension attacks that affect plain SHA hashes.

Which HMAC algorithm should I use?

Use HMAC-SHA256 for most applications—it's secure, widely supported, and the standard for most APIs (AWS, Stripe, GitHub). Use HMAC-SHA512 for extra security margin. HMAC-SHA1 is acceptable for OAuth 1.0 compatibility. Avoid HMAC-MD5 unless required for legacy compatibility.

Related Tools

Explore other tools you might find useful:

Related Calculators