HMAC Generator
Enter your message text and secret key, then select a hash algorithm to generate the HMAC signature.
Reviewed by the ToolNestr Editorial Team — July 2026
How HMAC works
HMAC (Hash-based Message Authentication Code) combines a secret key with a cryptographic hash function using a specific two-step construction. The key is XORed with an inner padding constant (ipad = 0x36 repeated to block size) and concatenated with the message, then hashed. The result is then concatenated with the key XORed with an outer padding constant (opad = 0x5C repeated) and hashed again.
This dual-hash construction provides provable security: HMAC is secure as long as the underlying hash function is collision-resistant against chosen-message attacks. The nested approach also prevents length-extension attacks that could break simpler constructions like H(key || message).
Worked example
HMAC use cases by popularity
HMAC is used across many security contexts. Here is how it breaks down by real-world usage.
API Developer
Implements HMAC-signed API requests to authenticate clients and verify request integrity without exposing secrets in transit.
Backend Engineer
Uses HMAC for service-to-service authentication in microservice architectures, ensuring messages between components are authentic.
Security Architect
Designs authentication systems using HMAC for token validation, session management, and secure channel establishment.
DevOps Engineer
Configures webhook endpoints with HMAC verification to ensure incoming notifications from CI/CD pipelines are genuine.
| Algorithm | Output Length (hex) | Block Size | Security Level |
|---|---|---|---|
| HMAC-MD5 | 32 chars | 64 bytes | Adequate for legacy |
| HMAC-SHA1 | 40 chars | 64 bytes | Acceptable |
| HMAC-SHA256 | 64 chars | 64 bytes | Strong — recommended |
| HMAC-SHA512 | 128 chars | 128 bytes | Strongest |
How to use HMAC Generator
Enter message and key
Type the message you want to authenticate and a secret key. The key should be a random string known only to the parties exchanging data.
Select algorithm and format
Choose the hash algorithm and output format. SHA-256 with hex output is recommended for most applications.
Copy the HMAC output
Click Generate to compute the HMAC, then copy the result. Include it with your message for verification by anyone with the same key.
Tips for using HMAC
Use a strong, random key
Generate your HMAC key using a cryptographically secure random generator. For HMAC-SHA256, use at least 32 bytes (256 bits) of randomness. Weak or predictable keys defeat the purpose of HMAC.
Never share the key in the message
The security of HMAC depends on keeping the key secret. Never include the key in the message being authenticated. Distribute keys through secure channels like key management services.
Use constant-time comparison for verification
When verifying HMACs, always use a constant-time comparison function. Simple string comparison is vulnerable to timing attacks that leak the expected HMAC byte by byte.
What is HMAC?
HMAC (Hash-based Message Authentication Code) is a specific construction for creating a message authentication code (MAC) using a cryptographic hash function and a secret key. It was standardized as RFC 2104 in 1997 and remains one of the most widely used authentication mechanisms in modern security protocols.
The HMAC construction uses two passes of the hash function: first, the key XORed with an inner padding (ipad) is hashed together with the message; then the result is hashed again with the key XORed with an outer padding (opad). This dual-hash approach provides resistance against length-extension attacks that could compromise simpler constructions like H(m || k).
How HMAC Works
HMAC is computed as: HMAC(K, m) = H((K' ⊕ opad) || H((K' ⊕ ipad) || m)), where H is the chosen hash function, K is the secret key, K' is the key padded to the block size, ipad and opad are constant padding bytes (0x36 and 0x5C repeated). The XOR operations ensure that the key influences both the inner and outer hash computations.
This construction provides provable security: if the underlying hash function is collision-resistant, HMAC is secure against forgeries even against chosen-message attacks. The security proof holds even for hash functions with weaker collision resistance, which is why HMAC-MD5 remains viable despite MD5's vulnerabilities.
HMAC in API Authentication
Many REST APIs use HMAC for request authentication. The client creates a signature by computing HMAC over parts of the request (method, path, body, timestamp) using a shared secret key. The server recomputes the signature and verifies it matches. This proves the request came from someone possessing the key and prevents replay attacks when timestamps are included.
Major platforms using HMAC for API authentication include AWS (Signature Version 4), Google Cloud API keys, and various payment gateways. The HMAC signature binds the request to a specific key, timestamp, and message content, ensuring that intercepted requests cannot be modified or replayed.
Webhook Verification with HMAC
Webhook providers like Stripe, GitHub, and Slack use HMAC to sign webhook payloads. When a provider sends a webhook, it includes an HMAC signature header computed over the request body using a shared secret. The receiving application verifies the signature before processing the payload, ensuring it genuinely came from the provider and wasn't tampered with.
This verification is critical because webhooks often trigger sensitive operations like processing payments, deploying code, or updating databases. Without HMAC verification, an attacker who discovers the webhook URL could send forged events. Always verify HMAC signatures on incoming webhook requests.
Frequently asked questions
What is HMAC?
HMAC (Hash-based Message Authentication Code) is a construct that combines a secret key with a hash function to produce a verifiable authentication code. It ensures both message integrity and authenticity.
How does HMAC work?
HMAC works by hashing the key XORed with an inner pad concatenated with the message, then hashing the result with the key XORed with an outer pad. This two-step process provides security against length-extension attacks.
What algorithms can HMAC use?
HMAC can use any cryptographic hash function including MD5, SHA-1, SHA-256, and SHA-512. The security of HMAC depends on the underlying hash function.
Is HMAC with MD5 secure?
HMAC-MD5 is still considered secure for authentication despite MD5's collision weaknesses. The HMAC construction protects against the collision attacks that break plain MD5. However, HMAC-SHA256 is recommended for new systems.
What is HMAC used for?
HMAC is widely used for API authentication (AWS signatures, JWT validation), webhook verification, data integrity checks, and secure communication protocols like TLS.
What is the difference between HMAC and a simple hash?
A simple hash like MD5("message") can be computed by anyone. HMAC uses a secret key, so only parties knowing the key can create or verify valid authentication codes.
What output formats does HMAC support?
HMAC output is a binary value that can be represented in hexadecimal (hex) or Base64. Hex is more readable and standard; Base64 is more compact.
Is my data private when using this tool?
Yes. The tool uses the Web Crypto API for SHA-based HMAC and a pure JS implementation for MD5 HMAC. All processing happens locally in your browser.
How long should my HMAC key be?
For HMAC-SHA256, the key should be at least 32 bytes (256 bits). For HMAC-SHA512, use 64 bytes (512 bits). Shorter keys reduce security; longer keys are hashed down to the block size.
Can HMAC be used for encryption?
No. HMAC is an authentication code, not encryption. It proves who created the message and that it hasn't been modified, but the message itself is still readable without the key.