.env · create🔥 popular🔒 100% client-side — never leaves your browser

Random Secret Generator for JWT, API Keys and Sessions

Generate a random secret key for your .env in one click: this secret generator creates JWT secrets, session secrets, hex API keys and strong passwords from your browser's cryptographic random number generator. Nothing is sent anywhere.

By Aliniyaz Mamat · last reviewed

Be the first to rate
generated locally with crypto.getRandomValues
JWT Secret (base64url, 48 bytes)
NextAuth, JWT, NEXTAUTH_SECRET
JWT Secret (base64url, 64 bytes)
HS512 / maximum entropy
API Key (hex, 16 bytes)
Short API tokens
API Key (hex, 32 bytes)
Standard API tokens
Session Secret (base64url, 32 bytes)
Express sessions, CSRF
Password (20 chars, symbols)
DB passwords, admin accounts. Contains # and $: use KEY='…' in .env
Password (32 chars, symbols)
High-security accounts. Contains # and $: use KEY='…' in .env
Password (16 chars, no symbols)
Shell-safe, URL-safe

Key takeaways

  • ✓Every value comes from crypto.getRandomValues, the same OS entropy source as openssl rand and Python's secrets.
  • ✓"48 bytes" means 48 random bytes: 384 bits, shown as 64 base64url characters. 32 bytes (256 bits) is enough for any HMAC or session secret today.
  • ✓Hex is the safest format for config files and URLs (0-9a-f only). base64url is shorter for the same entropy.
  • ✓Passwords with symbols contain # and $: wrap them in single quotes in a .env file, or dotenv cuts them at #.
  • ✓Use one secret per purpose and per environment. Reusing a secret turns one leak into several.

What it does

  • ▸JWT secrets: 48 and 64 random bytes, base64url
  • ▸Session secret: 32 random bytes, base64url
  • ▸API keys: 16 or 32 random bytes as hex
  • ▸Passwords: 16, 20 and 32 characters, with or without symbols
  • ▸Regenerate one value or all, 100% client-side

Privacy

Runs 100% in your browser. Your .env never touches our servers.

client-side only

When to use this tool

  • →JWT_SECRET, SESSION_SECRET, COOKIE_SECRET and ENCRYPTION_KEY in a new project
  • →Database and Redis passwords for docker-compose
  • →Internal API keys between your own services
  • →Replacing placeholder values like changeme before a deploy

Common mistakes

  • ⚠Inventing secrets by hand: human-made strings are short and guessable
  • ⚠Using Math.random() or a UUID v4 as a secret. UUIDs have only 122 random bits and a fixed, recognisable format
  • ⚠Pasting a symbol password unquoted into .env: DB_PASS=ab#cd is read as ab
  • ⚠Sharing secrets in chat or tickets. Use your team's password manager or the ENV encrypt tool

Which secret format for which variable

VariableRecommended presetWhy
JWT_SECRET (HS256)JWT 48 bytes≥ 32 bytes required for HS256; more is fine
JWT_SECRET (HS512)JWT 64 bytesHS512 needs ≥ 64 bytes
SESSION_SECRET, COOKIE_SECRETSession 32 bytesExpress/Fastify sign cookies with HMAC-SHA256
API_KEY for your own servicesAPI key hex 32 bytesURL- and header-safe, easy to compare in logs
DB_PASSWORD, REDIS_PASSWORDPassword 32 chars, or no-symbols 16+symbols need quoting in URLs and .env
ENCRYPTION_KEY (AES-256)API key hex 32 bytesexactly 32 bytes = 256-bit key

Framework-specific formats have their own pages: NextAuth AUTH_SECRET, Django SECRET_KEY, Laravel APP_KEY, Rails SECRET_KEY_BASE and WordPress salts.

How strong is strong enough?

PresetRandom bitsLength
API key hex, 16 bytes12832 characters
Session secret, 32 bytes25643 characters
API key hex, 32 bytes25664 characters
JWT secret, 48 bytes38464 characters
JWT secret, 64 bytes51286 characters
Password, 20 chars with symbols (88-char alphabet)about 12920 characters

128 random bits cannot be brute-forced with any foreseeable hardware; 256 bits adds margin and matches what HMAC-SHA256 and AES-256 expect. Length beyond that mostly costs readability.

Generating secrets on the command line

openssl rand -hex 32          # 64 hex chars, 256 bits
openssl rand -base64 32       # 44 chars, 256 bits
node -e "console.log(require('crypto').randomBytes(32).toString('base64url'))"
python -c "import secrets; print(secrets.token_urlsafe(32))"

All of these use the operating system's CSPRNG, like this page. The OpenSSL rand generator shows the exact output format of each openssl rand variant. Before a release, scan your .env for weak or placeholder values with the ENV leak checker.

Frequently asked questions

How is the randomness generated?

With the Web Crypto API (crypto.getRandomValues), which reads from the operating system's cryptographically secure random number generator. There is no fallback to Math.random().

Is there a difference between hex and base64 secrets?

Only the encoding. 32 random bytes are 64 characters as hex or 43 as base64url; both carry 256 bits. Hex is easier to handle in shells and URLs, base64url is shorter.

What length should I choose?

32 bytes (256 bits) for HMAC, session and encryption keys. 48 or 64 bytes only if your algorithm requires it, e.g. HS512 needs 64.

Is it safe to use these secrets in production?

Yes. They are generated locally and never transmitted. Copy them straight into your host's secret settings or your password manager, and generate separate values for each environment.

Why does my password stop working when I put it in .env?

Unquoted, # starts a comment and $ may be expanded. Write it as DB_PASSWORD='…' in single quotes, or use the no-symbols preset.

Related tools

Learn more

coming soon

Get notified when env syncing launches

We're building a tiny tool to keep .env files in sync across teammates and environments. Leave your email — no spam, just a single launch ping.

We use your address only for this launch email. You can ask us to delete it at any time. Privacy policy