Skip to content
Aarrange

Secret Key Generator

Make a JWT secret, a Django SECRET_KEY, a Laravel APP_KEY or a 256-bit key in one click. Or paste secrets to check them. Nothing leaves your browser.

0
Secrets
0
Lowest bits
0
Issues
Input
Tab types a tab. Press Escape, then Tab, to leave the editor.
Result

Your new secret

Press Generate (Alt G) to put it in the editor, or paste secrets there to check them.

On this page

About Secret Key Generator

Updated

Secret Key Generator makes the secrets that apps and frameworks need: a JWT secret, a Django SECRET_KEY, a Laravel APP_KEY, an Auth.js AUTH_SECRET, or a plain 256-bit key. Each one has the shape the framework expects, from your browser's secure random source. The secret never leaves your browser.

It also checks secrets. Paste a .env file, and each secret gets its length, its bits and its strength. Settings such as APP_NAME or DB_PORT are skipped. A short secret, a hidden space or a look-alike letter is marked. For API keys with a prefix and a checksum, use the API Key Generator. For plain strings and codes, use the Random String Generator.

How to generate a secret key

  1. Pick the secret in Format, next to Generate. On a phone it is under More. The start setting is a JWT secret for HS256. For Hex or Base64, set Bytes next to Format.
  2. Press Generate (Alt G), and copy the secret. The Result shows a fresh one before you press anything.
  3. Put it in your .env file or your secret manager. Make a different secret for each app and each stage, such as test and production.
  4. To check secrets, paste them one per line, or paste the whole .env file. Results shows each one with its strength, and Notes lists what is wrong.
  5. Open Code to make the same secret in your own program or deploy script.

Which secret to pick

  • JWT secret (HS256): 32 bytes in Base64 URL-safe, 43 characters. For JWT_SECRET in jsonwebtoken, jose, PyJWT and most JWT libraries.
  • Django SECRET_KEY: 50 characters, 282 bits. For SECRET_KEY in a Django project.
  • Laravel APP_KEY: base64: and 32 bytes, 51 characters. For APP_KEY in a Laravel .env file.
  • Auth.js / NextAuth secret: 32 bytes in Base64, 44 characters. For AUTH_SECRET or NEXTAUTH_SECRET.
  • openssl rand -hex 32 and openssl rand -base64 32: the same output as the shell command, for any app that asks for one.
  • Hex, Base64 and Base64 URL-safe with your own Bytes: 48 or 64 bytes for HS384 and HS512, or 32 bytes for an AES-256 key.

Common errors

A secret that is too short

Tutorials often use a word such as mysecret. With one signed token, anyone can guess a short secret on their own computer and then make tokens that your server accepts.

Invalid
JWT_SECRET=mysecret

Tool:41 bits. A secret needs 128 or more.

Fixed
JWT_SECRET=ba20fYi5JH7RMC5KZDGmCyCjSkos9-fmv_SC05SNSuo

A space at the end

A secret copied from a terminal or a chat often brings a space with it. The app then reads a different secret: every token or cookie fails, and the secret looks right.

Invalid
APP_KEY=base64:oe0DJDwcLDioCzS05+9paKMmdfbNH4DeallCiFEZSo0=␣

Tool:A space at the end. A secret with a space in it fails in a header or a .env file. Delete it.

Fixed
APP_KEY=base64:oe0DJDwcLDioCzS05+9paKMmdfbNH4DeallCiFEZSo0=

Secret key resources

Secret key FAQ

How can I generate a JWT secret?

Press Generate on this page. The start setting is JWT secret (HS256): 32 random bytes from your browser's secure random source, written in Base64 URL-safe. That is 43 characters and 256 bits.

In a shell, openssl rand -base64 32 gives a secret of the same strength. In Node.js, use crypto.randomBytes(32).toString("base64url"). In Python, use secrets.token_urlsafe(32).

What is a JWT secret?

The shared key that HS256, HS384 and HS512 use to sign a JWT and to check it. The algorithm is HMAC: it mixes the secret into a hash of the token. Anyone who has the secret can make tokens that your server accepts.

Keep it on the server, in an environment variable or a secret manager. Never put it in the token, in browser code or in Git. To check a token's signature with your secret, use the JWT Decoder.

How long should a JWT secret be?

At least as long as the hash: 256 bits (32 bytes) for HS256, 384 bits (48 bytes) for HS384 and 512 bits (64 bytes) for HS512. RFC 7518 sets this rule. For HS384 or HS512, pick Base64 URL-safe in Format and set Bytes to 48 or 64.

A word or a phrase is not a secret. With one token, a guesser can test billions of secrets per second on their own computer, and no rate limit stops them.

How do I generate a Django secret key?

Pick Django SECRET_KEY in Format and press Generate. You get 50 characters from a-z, 0-9 and !@#$%^&*(-_=+), the same set as Django's own get_random_secret_key(). That is 282 bits.

In a shell: python -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())". Load the key from an environment variable, not from settings.py in Git. The key can have $ and #: in a .env file, put it in single quotes.

How do I make a Laravel APP_KEY?

In a Laravel project, php artisan key:generate writes a new key to .env. Without the project, pick Laravel APP_KEY here: base64: and 32 random bytes in Base64, 51 characters in all.

Laravel encrypts cookies, sessions and encrypted fields with this key (AES-256-CBC). A new key logs every user out and makes old encrypted data unreadable. To change it safely, put the old key in APP_PREVIOUS_KEYS.

Can I use openssl rand -base64 32?

Yes. It gives 32 random bytes as 44 Base64 characters: 256 bits. That is strong enough for a JWT secret, an Auth.js AUTH_SECRET and most app secrets. openssl rand -hex 32 gives the same 32 bytes as 64 hex digits.

This page makes both: pick them in Format. For Laravel, the key also needs base64: in front, so pick Laravel APP_KEY.

What is a 256-bit key?

32 random bytes. As text, that is 64 hex digits, 44 Base64 characters or 43 Base64 URL-safe characters. HS256 and AES-256 take a key of this size. A 256-bit key must come from a secure random source, not from a password: a password of 32 characters has far fewer than 256 bits.

Are my secrets sent anywhere?

No. The tool makes and checks secrets in your browser, with the Web Crypto API. Nothing is uploaded and nothing is logged. You can check this in your browser's network tab while you press Generate.