How to use the jwt secret generator
- Select the HMAC algorithm your application uses: HS256, HS384 or HS512.
- Click Generate to create a new cryptographically random secret.
- Copy the key in your preferred encoding: hex, standard base64 or base64url.
- Paste the secret into your server configuration or environment variables.
Why key size matters for JWT HMAC
The JSON Web Signature specification (RFC 7518) requires that an HMAC key be at least as long as the hash output of the chosen algorithm. If you use a shorter key, the effective security drops below the intended level. A jwt secret generator must therefore produce keys of exactly 32 bytes for HS256, 48 bytes for HS384 and 64 bytes for HS512.
For example, HS256 relies on SHA-256, which outputs 256 bits (32 bytes). Supplying a 16-byte key means an attacker only needs to search 128 bits of space rather than 256, halving the security margin. Using a key longer than the hash block size does not add meaningful strength because the algorithm hashes the oversized key down to the output length before processing.
Output encodings explained
Different frameworks expect secrets in different string formats. This tool provides three common representations so you can copy the one your library requires without manual conversion.
| Encoding | HS256 length | Character set |
|---|---|---|
| Hexadecimal | 64 characters | 0-9, a-f |
| Base64 | 44 characters | A-Z, a-z, 0-9, +, /, = |
| Base64url | 43 characters | A-Z, a-z, 0-9, -, _ |
Hex is the most readable and avoids any padding ambiguity. Standard base64 is compact but includes + and / characters that may need escaping in URLs or configuration files. Base64url replaces those two characters with - and _ and omits trailing = padding, making it safe for HTTP headers and query strings.
How the randomness is generated
The secret bytes come from crypto.getRandomValues(), the Web Cryptography API available in every modern browser. This function draws from the operating system's cryptographic random number generator (such as /dev/urandom on Linux or BCryptGenRandom on Windows), which gathers environmental noise to maintain a high-entropy pool.
Because the generation happens entirely in JavaScript within your browser session, the raw bytes never leave your machine. No network request is made and this tool does not store the secret anywhere. This makes the jwt secret generator suitable for creating production credentials.
Storing and rotating your JWT secret
Never commit a JWT signing key to source control. Store it in an environment variable, a secrets manager such as HashiCorp Vault or AWS Secrets Manager, or an encrypted configuration file that is excluded from version control via .gitignore.
Rotate the secret periodically or immediately if you suspect exposure. During rotation, keep the old key active for a short overlap window so that tokens signed just before the change can still be verified. Once all clients have refreshed their tokens, remove the old key. You can verify existing tokens after a rotation using a jwt expiration checker to ensure none outlive the transition period.
Common mistakes to avoid
Developers frequently weaken JWT security through simple oversights. Here are the most common pitfalls:
- Using a human-readable passphrase. A phrase like "my super secret" has far fewer than 256 bits of entropy. Always use a random byte sequence from a proper jwt secret generator.
- Reusing the same key across environments. Development, staging and production should each have distinct secrets so a leak in one cannot compromise another.
- Mixing up symmetric and asymmetric algorithms. HS256, HS384 and HS512 are symmetric: the same key signs and verifies. If you need separate signing and verification keys, switch to RS256 or ES256 instead.
- Hard-coding the secret in client-side code. Any value shipped to the browser can be extracted by a user. Symmetric JWT keys belong exclusively on the server.
Worked examples
| Example | Input | Result |
|---|---|---|
| HS256 secret | Algorithm: HS256 | Algorithm: HS256; Entropy: 256 bits; Hex: 9b9137964b955e60181670b0ee0a45e1b8c357a796344cea2d36da9a33ca1e6b; Base64: m5E3lkuVXmAYFnCw7gpF4bjDV6eWNEzqLTbamjPKHms=; Base64url: m5E3lkuVXmAYFnCw7gpF4bjDV6eWNEzqLTbamjPKHms |
| HS384 secret | Algorithm: HS384 | Algorithm: HS384; Entropy: 384 bits; Hex: f77807f794e062e0f2b8df856884737eedf43df5295f520ee715a9315e8ae9e90e44f927b7be7cfce5b5572914801b4c; Base64: 93gH95TgYuDyuN+FaIRzfu30PfUpX1IO5xWpMV6K6ekORPknt758/OW1VykUgBtM; Base64url: 93gH95TgYuDyuN-FaIRzfu30PfUpX1IO5xWpMV6K6ekORPknt758_OW1VykUgBtM |
| HS512 secret | Algorithm: HS512 | Algorithm: HS512; Entropy: 512 bits; Hex: ec67b460328ad4a782abc2b45d1743a0d2c0c3075d0d553585fa326e118a9a33108c54f84837d912d8ec0e6c84a31e35a91709ca012ba9033aad3c177c92d4fe; Base64: 7Ge0YDKK1KeCq8K0XRdDoNLAwwddDVU1hfoybhGKmjMQjFT4SDfZEtjsDmyEox41qRcJygErqQM6rTwXfJLU/g==; Base64url: 7Ge0YDKK1KeCq8K0XRdDoNLAwwddDVU1hfoybhGKmjMQjFT4SDfZEtjsDmyEox41qRcJygErqQM6rTwXfJLU_g |
FAQ
What is the minimum key length for HS256?
RFC 7518 requires the key to be at least 256 bits (32 bytes) for HS256. Shorter keys reduce the effective security below what the algorithm is designed to provide.
Can I use the same secret for HS256 and HS512?
Technically you could pass the same bytes to both, but it is poor practice. Each algorithm should have its own dedicated key so that compromising one does not affect the other.
Is this jwt secret generator safe for production keys?
Yes. It uses the browser's built-in cryptographic random number generator and performs all computation locally. No data is sent over the network.
Which encoding format should I choose?
Use hex if your framework documentation shows hex examples. Use base64url if the key will appear in URLs or HTTP headers. Otherwise standard base64 works well for most server-side libraries.
How often should I rotate my JWT secret?
There is no universal rule, but many teams rotate every 90 days or whenever personnel with access changes. Rotate immediately if you suspect the key has been exposed.
What is the difference between HS256 and RS256?
HS256 uses a single shared secret for both signing and verifying tokens. RS256 uses an asymmetric key pair: a private key to sign and a public key to verify, which is safer when multiple services need to validate tokens without holding the signing key.