Secret Key Generator – Generate a Random Secret Key
Generate a random secret key in seconds. Pick a format and length, then copy it into your .env file or secrets manager.
Keys are created in your browser with the Web Crypto API and are never sent to our servers.
Use the Copy button to copy the secret key to your clipboard
Pick the right format and length
- Hex: 64 characters gives 256 bits. Easy to paste anywhere.
- Base64 (URL-safe): about 43 characters gives 256 bits. Shorter than hex.
- Alphanumeric: readable and safe in most config files; use at least 43 characters for roughly 256 bits.
Generate a secret key in your terminal
If you prefer not to use a website for production secrets, these commands produce a 256-bit secret locally:
openssl rand -hex 32
openssl rand -base64 32
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
python3 -c "import secrets; print(secrets.token_hex(32))"What a secret key is used for
- Signing session cookies (Express, Django, Rails, Laravel).
- Signing JSON Web Tokens with HS256, HS384 or HS512. See the JWT secret key generator and the JWT token generator.
- Verifying webhook signatures and signing CSRF tokens. For service credentials use the API key generator.
Keep your secret key safe
- Never commit it to Git; load it from an environment variable.
- Use a different secret for development, staging and production.
- Rotate it immediately if it may have been exposed.
Related guide: How to set JWT_SECRET in a .env file.
Frequently asked questions
What is a secret key?
A secret key is a random value that only your application knows. It is used to sign or encrypt data, for example session cookies, JWTs, CSRF tokens or webhook signatures, so that outsiders cannot forge or read it.
How long should a secret key be?
Use at least 32 random bytes (256 bits) for general-purpose signing secrets. In hex that is 64 characters, in Base64 about 43 characters. Longer is fine, shorter is not.
Is it safe to generate a secret key in a browser?
Yes, when the page uses the Web Crypto API (crypto.getRandomValues), as this tool does. The key is generated on your device and is never transmitted to our servers. For production secrets you can also generate one locally with the openssl command shown below.
Where should I store a secret key?
In an environment variable or a secrets manager, never in source control. Use a different secret per environment and rotate it if it may have leaked.
Can I use this secret for a JWT?
Yes, for HMAC algorithms such as HS256, HS384 and HS512. If you need a key sized for a specific algorithm, use the JWT secret key generator on our home page.