The Golden Rule of RFC 7518 (Section 3.2)
Using a secret shorter than the hash output size exposes your authentication system to offline dictionary attacks and rainbow table matching.
Entropy vs. String Length: The Common Misconception
# Generate 256 bits (32 raw bytes) of true cryptographic randomness in Hex:
openssl rand -hex 32
# Or in Base64:
openssl rand -base64 32Required Key Lengths by HMAC Algorithm
Need a cryptographically secure JWT secret right now?
Generate 128 to 512-bit keys in Hex or Base64 using Web Crypto with zero server transmission.
Frequently Asked Questions
Can I use a 128-bit key for HS256?
Technically the math works, but it strictly violates RFC 7518 Section 3.2. Modern security audit tools and linters will flag 128-bit keys as a critical security vulnerability.
Does a Base64-encoded secret provide more security than Hex?
No. Base64 and Hex are simply representation encodings. The underlying entropy is strictly determined by the number of random bytes (e.g., 32 bytes = 256 bits), regardless of how it is serialized.
Related Technical Guides
HS256 Secret Key Requirements: Specifications, Code Examples, and Common Traps
Learn the official RFC 7518 requirements for HS256 JWT keys. Understand key derivation, minimum byte lengths, and implementation examples.
Secret GenerationHow to Generate a Secure JWT Secret in Node.js, Linux CLI, and Python
Step-by-step guide to generating production-ready JWT secrets using OpenSSL, Node.js crypto, Python secrets, and modern browser Web Crypto.