Secret key generator

A cryptographically random key, in the format your tool expects, with the line ready to paste into your .env file.

Your key
Line ready to paste into your .env

Send with onlyU — Your recipient gets a link they can open only once, then the link is gone. onlyU opens in a new tab with the secret already filled in: all you have to do is create the link. Free, no sign-up. How does it work?

Computed in your browser. Nothing is sent unless you choose onlyU.

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's get_random_secret_key() function.
  • Laravel APP_KEY: base64: followed by 32 bytes in base64, the form produced by php artisan key:generate.
  • NEXTAUTH_SECRET or AUTH_SECRET: 32 bytes in base64, the equivalent of openssl 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_KEY invalidates sessions and pending password reset links; since Django 4.1, SECRET_KEY_FALLBACKS keeps the old one during the transition;
  • a new Laravel APP_KEY can no longer decrypt what the old one encrypted; since Laravel 11, APP_PREVIOUS_KEYS keeps 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.

Frequently asked questions

How long should a secret key be?

32 bytes (256 bits) suit almost every use: API key, HS256 signing secret, AES-256 key. For HS512, use 64 bytes, the size of a SHA-512 hash and the minimum set by RFC 7518.

Why not just type a random key on the keyboard?

A string typed “at random” isn't random: your hands follow patterns. A key must come from a cryptographic generator, like your browser's, which this tool uses.

Hexadecimal, Base64 or base62: what's the difference?

They are three ways of writing the same bytes. Hexadecimal is the most readable, Base64 the most compact, and base62 uses only letters and digits, which avoids any escaping issue in a URL or a configuration file.

Where should I store the generated key?

In an environment variable or a secrets vault (Azure Key Vault, AWS Secrets Manager, HashiCorp Vault…), never in source code or a Git repository. Your .env file should be listed in your .gitignore.

How do I share the key with a colleague?

Through a channel that doesn't keep it: “Send with onlyU” creates a link that opens only once. The key doesn't linger in a mailbox or a chat history.