JWT Secret Generator

Generate a cryptographically random secret for signing JWTs with HS256, HS384 or HS512. Created on your device, never sent anywhere.

JWT_SECRET

Generating in your browser…

Generated on your device with the Web Crypto API. Never sent or stored.

.env line
JWT_SECRET=""

Prefer the terminal?

  • OpenSSL
    openssl rand -base64 64
  • Node.js
    node -e "console.log(require('crypto').randomBytes(64).toString('base64'))"
  • Python
    python3 -c "import secrets; print(secrets.token_urlsafe(64))"

How to use your JWT secret

Copy the value above and add it to your server's environment as JWT_SECRET, then pass it to your JWT library's sign and verify calls. Keep it out of source control: commit an .env.example with an empty value instead, and set the real value in your hosting provider's environment settings or a secrets manager.

HMAC-signed tokens are only as strong as the key. RFC 7518 requires a key at least as long as the hash output: 32 bytes for HS256, 48 for HS384 and 64 for HS512. This page defaults to 64 bytes, which works for all three. If several services verify the same tokens, consider switching to an asymmetric algorithm such as RS256 or EdDSA so only one service holds the signing key.

Is it safe to generate secrets in a browser?

Only if the secret is created locally, which is how this page works. The value comes from crypto.getRandomValues, the same cryptographically secure source browsers use for TLS keys, and it never leaves your device: there is no network request, log or analytics event that includes it.

If you prefer the command line, the commands on this page produce an equivalent secret on your own machine. Either way, use a different secret for development, staging and production, and rotate it straight away if it ever appears in a log, a screenshot or a public repository.

Frequently asked questions

How long should a JWT secret be?

At least as long as the hash output: 32 bytes (256 bits) for HS256, 64 bytes for HS512. RFC 7518 requires a key of at least the hash size.

Should I commit my JWT secret to Git?

No. Put it in an environment variable or a secrets manager and rotate it if it ever leaks.