A random key, in the format your tool expects
A secret key protects an API, signs tokens or encrypts data: its only required quality is to be unpredictable.
The generator draws its bytes with your browser's cryptographic random number generator
(crypto.getRandomValues), then writes them in the encoding your framework expects. Each preset
also shows the line ready to paste into your .env file, for example
APP_KEY=base64:….
The key exists only in this page. The page is not allowed to make a single network request: the key goes nowhere unless you choose to send it.
The presets
- API key: an optional prefix (for example
sk_) followed by 32 random bytes in base62 or hexadecimal. The prefix tells at a glance what the key is for, and helps secret scanning tools spot it if it ends up in a repository. - JWT secret, HS256 or HS512: 32 or 64 bytes in base64url. RFC 7518 requires a key at least as long as the hash output: 256 bits for HS256, 512 bits for HS512.
- AES-128 or AES-256 key: 16 or 32 bytes, in hexadecimal or base64, for an encryption library that expects the raw key.
- Django
SECRET_KEY: 50 characters drawn from the same alphabet as Django'sget_random_secret_key()function. - Laravel
APP_KEY:base64:followed by 32 bytes in base64, the form produced byphp artisan key:generate. NEXTAUTH_SECRETorAUTH_SECRET: 32 bytes in base64, the equivalent ofopenssl rand -base64 32, for NextAuth.js and Auth.js.- Custom: the number of bytes and the encoding of your choice, for any other use.
Reading the result
Hexadecimal, base64, base64url and base62 are four ways of writing the same bytes. Hexadecimal doubles the
length (64 characters for 32 bytes); base64 is more compact (44 characters, including a trailing
=); base64url replaces + and / with - and _ so
it can travel unescaped in a URL or a header; base62 uses only letters and digits. Some JWT libraries decode
the secret, others use the string as is: either way, it carries all the randomness drawn.
Django's SECRET_KEY contains symbols such as $ or #. If the tool that
reads your .env file interprets them (Docker Compose, for example, treats $ as a
variable), wrap the value in single quotes.
Before replacing an existing key
Changing a key in production has effects worth knowing before you paste the new one:
- a new JWT secret invalidates every token already issued: users will have to log in again;
- a new Django
SECRET_KEYinvalidates sessions and pending password reset links; since Django 4.1,SECRET_KEY_FALLBACKSkeeps the old one during the transition; - a new Laravel
APP_KEYcan no longer decrypt what the old one encrypted; since Laravel 11,APP_PREVIOUS_KEYSkeeps it for decryption; - a new AES key means decrypting and then re-encrypting the existing data.
Share the key without leaving it lying around
When a colleague needs to set the key on a server, “Send with onlyU” hands them the line ready to paste. onlyU encrypts it in your browser and creates a link they can open only once, valid for 24 hours, after which the link disappears: the key does not linger in a ticket or a chat history. To go further, read our guide on how to generate and store a secret key.