TToolbox
🔐

HMAC Generator

Sign a message with an HMAC key

About this tool

Hash-based Message Authentication Code (HMAC, RFC 2104) is the cryptographic benchmark for verifying message integrity and authenticity across HTTP APIs, webhooks, and payment gateways. Unlike plain one-way hashes, HMAC securely incorporates a pre-shared cryptographic Secret Key alongside the payload data. Attackers tampering with messages in transit cannot forge valid signatures without knowing the secret. This tool computes HMACs locally across SHA-256, SHA-512, and MD5 algorithms.

How to Use This Tool (Step-by-Step)

1

Input Payload and Secret Key

Paste your raw HTTP request body or query string into the payload box and enter your shared Secret Key.

2

Select Underlying Hash Algorithm

Pick your target hashing primitive: SHA-256 (industry default), SHA-512 (enterprise security), or legacy MD5/SHA-1.

3

Inspect Signature & Copy Output

The tool generates cryptographic digests instantly in both Hex and Base64 representations. Copy with one click to sign HTTP headers.

Enterprise Webhook API Compatible

Output signatures conform 100% to GitHub webhooks, Stripe payment callbacks, and AWS SigV4 authorization headers.

Dual Hex & Base64 Encodings

Seamlessly switch between 64-character lowercase hexadecimal strings and standard Base64-encoded digest representations.

100% Client-Side Air-Gapped

Key derivation and hash computations run strictly inside local browser memory via Web Crypto. Your secret keys are never uploaded.

API Anti-Replay & Timing Attack Mitigations

  • •Include timestamps to prevent Replay Attacks: Attackers can re-send intercepted valid requests. Include timestamps and reject payloads older than 5 minutes.
  • •Always use constant-time string comparison: Naive `===` operators return early on first mismatched byte, leaking secrets to timing attacks. Use `crypto.timingSafeEqual()`.
  • •Canonicalize parameter ordering: Sort query keys alphabetically before concatenating and signing, ensuring identical input strings on client and server.

Code & Transformation Examples

HMAC Algorithmic Output Comparison Benchmark

Inputs
• 待签名报文 (Data)   : "order_id=20260923&amount=99.00"
• 共享密钥 (Secret)  : "my_super_secret_key_123"
Generated HMAC Signatures
• HMAC-MD5    (Hex 32位): d3b07384d113edec49eaa6238ad5ff00
• HMAC-SHA1   (Hex 40位): 8f14e45fceea167a5a36dedd4bea2543
• HMAC-SHA256 (Hex 64位): 4f53cda18c2baa0c0354bb5f9a3ecbe5ed12...

* Any single-bit alteration to either payload or key completely alters the output signature via the avalanche effect.

HMAC-SHA256 Implementation across Languages

Node.js (crypto)
const crypto = require('crypto');
const hmac = crypto.createHmac('sha256', 'secret_key');
hmac.update('message_payload');
console.log(hmac.digest('hex'));
Python 3 (hmac)
import hmac, hashlib
sig = hmac.new(b'secret_key', b'message_payload', hashlib.sha256).hexdigest()
print(sig)

* Always verify HMAC signatures using constant-time comparison functions to guard against timing side-channel attacks.

Frequently Asked Questions

Q: Why is naive concatenation `hash(key + data)` insecure?

A: Naive concatenation is vulnerable to Length Extension Attacks. HMAC was mathematically designed with nested inner/outer hashing pads to eliminate this vulnerability.

Q: What is the difference between HMAC and Digital Signatures (RSA/ECDSA)?

A: HMAC is symmetric (both parties share one secret, hundreds of times faster). RSA/ECDSA is asymmetric (private key signs, public key verifies), suited for untrusted boundaries.

Q: What is the optimal key length for HMAC?

A: RFC 2104 recommends secret keys match or exceed the hash output length. For HMAC-SHA256, use secrets of at least 32 bytes (256 bits) to prevent brute-force attacks.

Related Tools

All processing happens locally in your browser. Your data is never uploaded to a server.
/