Generate a JWT secret
Advanced generation
Generated in your browser. Copy writes to your clipboard.
Use the secret
Copy the key, then sign a test JWT →
Save the JWT_SECRET_B64URL line in a .env file next to the demo. The value is always unpadded Base64URL. The examples decode it before using it for HMAC.
Install
Run
JWT_SECRET_B64URL=<your-base64url-secret>
Secret setup help
Keep secrets out of source control.
How do I generate a JWT secret key?
A key is generated as soon as the page opens, so you only choose an algorithm and copy it. Under Algorithm pick HS256, HS384 or HS512. Leave Key length (bytes) at the minimum or raise it up to 256; changing either one makes a new key. Pick an Output encoding: Hex, Base64 or Base64URL, which keeps the same bytes. Then use Copy key, or Copy .env line under Use the secret for a ready JWT_SECRET_B64URL entry. Select Regenerate whenever you need a fresh key.
HMAC key lengths
| Algorithm | bit | B | Hex | Base64 | Base64URL |
|---|---|---|---|---|---|
| HS256 | 256 | 32 | 64 | 44 | 43 |
| HS384 | 384 | 48 | 96 | 64 | 64 |
| HS512 | 512 | 64 | 128 | 88 | 86 |
The minimum key size is 32 bytes for HS256, 48 for HS384 and 64 for HS512, because RFC 7518 §3.2 requires an HMAC key at least as large as the hash output. Changing the encoding keeps the same bytes: a 32-byte key is 64 Hex characters, 44 Base64 characters with padding, or 43 Base64URL characters without padding.
Frequently asked questions
Should access and refresh tokens use separate secrets?
A separate secret for refresh tokens is common best practice, not a requirement of the JWT or OAuth specifications. With two keys, leaking or rotating one does not touch the other, and a token signed for one purpose cannot pass as the other. Generate a second key here and store it under its own name, such as JWT_REFRESH_SECRET. OWASP's JWT cheat sheet accepts one shared key only when token type confusion is not a risk, so also check a type or audience claim. If your refresh tokens are opaque random strings stored on the server rather than signed JWTs, they need no signing secret at all.
How do I generate a JWT secret key from the command line?
Use OpenSSL, Node.js, Python or PowerShell; each command below prints 32 random bytes, the minimum for HS256, from a cryptographically secure generator. Plain cmd.exe has no built-in secure random generator, so open PowerShell instead, or call it with powershell -Command. The one-line PowerShell sample needs PowerShell 7.2 or later; on Windows PowerShell 5.1 use the second sample. The Node.js base64url output needs Node.js 14.18 or later. OpenSSL prints standard Base64 with +, / and =; pipe it through tr '+/' '-_' and tr -d '=' if you need Base64URL.
- OpenSSL, Base64 (44 characters)
openssl rand -base64 32- OpenSSL, Hex (64 characters)
openssl rand -hex 32- Node.js, Base64URL (43 characters)
node -e "console.log(require('crypto').randomBytes(32).toString('base64url'))"- Python, Base64URL (43 characters)
python3 -c "import secrets; print(secrets.token_urlsafe(32))"- PowerShell 7.2+, Base64 (44 characters)
[Convert]::ToBase64String([System.Security.Cryptography.RandomNumberGenerator]::GetBytes(32))- Windows PowerShell 5.1, Base64 (44 characters)
$b = New-Object byte[] 32; [System.Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($b); [Convert]::ToBase64String($b)
Does this generator use Base64 encoding?
By default it shows the key as Base64URL without padding, and you can switch to Hex or standard Base64 at any time; the random bytes underneath stay the same. A 32-byte key is 43 Base64URL characters, 44 Base64 characters or 64 Hex characters. The Copy .env line button always writes JWT_SECRET_B64URL as unpadded Base64URL, and the generated examples decode it before signing. Check how your library reads a string secret. jsonwebtoken, PyJWT and Hasura use the string as it is, so the encoded text itself becomes the key. The jose library needs bytes that you build yourself, and jjwt makes you choose a decoder. Either approach can work, as long as the signing and verifying sides read the string the same way.
What do I put in JWT_SECRET_KEY?
Put a long random string there: generate a key here and paste the Hex or Base64URL value, which avoids the +, / and = of standard Base64. Flask-JWT-Extended reads JWT_SECRET_KEY and falls back to Flask's SECRET_KEY if it is unset. django-graphql-jwt has a JWT_SECRET_KEY setting, defaulting to Django's SECRET_KEY, that GraphQL JWT uses to sign tokens. Hasura takes the key inside the HASURA_GRAPHQL_JWT_SECRET JSON next to the algorithm type, and for HS256 it must be at least 32 characters. Keep the value in an environment variable or secret store, not in source control, and use the same value on every service that verifies the tokens. The .env line from this page is named JWT_SECRET_B64URL on purpose; rename it to whatever your framework expects. If one service decodes the value to bytes first, every service that verifies the tokens must decode it the same way.
How long should a JWT secret be, and is a 32-character key enough?
Use at least 32 random bytes for HS256, 48 for HS384 and 64 for HS512. RFC 7518 §3.2 requires an HMAC key at least as large as the hash output, which is a size rule rather than an entropy rule. A 32-character string is 32 bytes as text, so it meets the HS256 size, but 32 random letters and digits carry about 190 bits of entropy, less than the 256 bits of 32 random bytes. That is still far beyond brute force, yet text needs 43 letters and digits to match a full HS256 key. Choose JWT random text under Advanced generation to get 43 characters for HS256 from the 62-character set, or 40 from the symbol sets. Byte mode accepts keys up to 256 bytes. Never use a password you can remember as the key.
Is this JWT secret key generator cryptographically secure?
Yes, keys come from crypto.getRandomValues, the browser's Web Crypto random number generator, not from Math.random. The bytes are generated on your device. In text mode the tool uses rejection sampling: it discards random bytes that would skew the result, so every character in the set is equally likely. This matches OWASP's advice that a JWT secret should come from a local, cryptographically secure generator.
Does this JWT secret key generator work offline, and is there a browser extension?
Once the page has loaded, generating a key needs no connection, and the key never leaves your browser. There is no browser extension, and you do not need one; bookmark the page to open it quickly. If usage statistics are enabled, they record things like the chosen algorithm, never the key or anything you type, and are skipped when Do Not Track or Global Privacy Control is on; see Usage statistics at the bottom of the page.