HMAC Generator

Generate HMAC authentication codes with SHA-256, SHA-384, SHA-512, or SHA-1. All computation happens in your browser.

Enter a message and secret key, then click Generate HMAC

What is HMAC?

HMAC (Hash-based Message Authentication Code) is defined in RFC 2104. It combines a cryptographic hash function with a secret key to produce an authentication tag that verifies both data integrity and authenticity. Unlike a plain hash, HMAC ensures that only parties possessing the secret key can generate or verify the tag.

Common Use Cases

API Authentication

AWS Signature V4, Stripe webhooks, GitHub webhooks all use HMAC-SHA256 to sign and verify requests.

JWT Signing

HS256, HS384, and HS512 JWT algorithms use HMAC with the corresponding SHA variant.

Webhook Verification

Services like Stripe, GitHub, and Shopify send HMAC signatures with webhooks for payload verification.

TOTP / HOTP

Time-based One-Time Passwords (RFC 6238) use HMAC-SHA1 to generate 2FA codes.

HMAC Algorithm Comparison

AlgorithmOutputSecurityUse Case
HMAC-SHA1160 bitsLegacyTOTP, OAuth 1.0
HMAC-SHA256256 bitsRecommendedAPIs, JWT (HS256), webhooks
HMAC-SHA384384 bitsStrongJWT (HS384), TLS
HMAC-SHA512512 bitsMaximumJWT (HS512), high security

Code Examples

Node.js

const crypto = require('crypto');
const hmac = crypto.createHmac('sha256', 'secret-key')
    .update('message')
    .digest('hex');

Python

import hmac, hashlib
result = hmac.new(b'secret-key', b'message', hashlib.sha256).hexdigest()

PHP

$hmac = hash_hmac('sha256', 'message', 'secret-key');

Frequently Asked Questions

What is HMAC?
HMAC (Hash-based Message Authentication Code) is a mechanism for verifying both the integrity and authenticity of a message. It combines a cryptographic hash function (like SHA-256) with a secret key to produce a fixed-size authentication tag.
What is HMAC used for?
HMAC is used for API authentication (AWS Signature V4, Stripe webhooks), JWT token signing, webhook payload verification, message integrity checking, and key derivation in protocols like TLS and IPsec.
Which HMAC algorithm should I use?
HMAC-SHA256 is the most widely recommended. It provides 256-bit security and is used by AWS, Stripe, GitHub, and most modern APIs. Use HMAC-SHA512 when you need extra security margin. Avoid HMAC-SHA1 for new applications.
Is HMAC-SHA1 still secure?
HMAC-SHA1 remains practically secure for message authentication, even though SHA-1 alone has collision vulnerabilities. The HMAC construction protects against collision attacks. However, HMAC-SHA256 is recommended for new implementations.
How is HMAC different from a plain hash?
A plain hash (like SHA-256) only verifies integrity — anyone can compute it. HMAC requires a secret key, so only parties who know the key can generate or verify the tag. This provides both integrity and authentication.
Is my data secure?
Yes. All HMAC computation happens entirely in your browser using the Web Crypto API. Your message and secret key are never sent to any server.