.env · security🔒 100% client-side — never leaves your browser

openssl rand Generator: -base64 and -hex in the browser

Run openssl rand -base64 32 or openssl rand -hex 32 without a terminal: this openssl rand generator produces the same output formats in your browser, from the same kind of OS-level cryptographic randomness, ready to paste into a .env file.

By Aliniyaz Mamat · last reviewed

Be the first to rate
Encoding
Bytes
Equivalent CLI command
openssl rand -base64 32
Output
Common use cases
openssl rand -base64 32— AUTH_SECRET, NEXTAUTH_SECRET
openssl rand -hex 32— API tokens, webhook secrets
openssl rand -base64 16— CSRF tokens, short-lived codes
openssl rand -hex 16— RAILS_MASTER_KEY

Key takeaways

  • ✓openssl rand -base64 N = N random bytes in standard base64: 32 bytes → 44 characters ending in =.
  • ✓openssl rand -hex N = N random bytes as lowercase hex: 32 bytes → 64 characters.
  • ✓Real OpenSSL wraps base64 output every 64 characters, so -base64 64 prints two lines. This page always gives one line, which is what a .env needs.
  • ✓Both commands draw from the OS CSPRNG; crypto.getRandomValues in the browser does the same.

What it does

  • ▸openssl rand -base64 and -hex equivalents
  • ▸Byte presets with the matching CLI command
  • ▸Single-line output, safe for .env files
  • ▸Common uses per command (AUTH_SECRET, API tokens, RAILS_MASTER_KEY)
  • ▸Generated locally, nothing transmitted

Privacy

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

client-side only

When to use this tool

  • →A README says "run openssl rand -base64 32" and you are on Windows without OpenSSL
  • →Generating AUTH_SECRET / NEXTAUTH_SECRET (-base64 32)
  • →API tokens and webhook secrets (-hex 32)
  • →Checking what a command's output should look like before scripting it

Common mistakes

  • ⚠Using openssl rand -base64 64 in a script without removing the line break: the variable gets a newline in the middle
  • ⚠Confusing bytes and characters: -hex 32 gives 64 characters, -base64 32 gives 44, both with 256 bits
  • ⚠Using base64 output in a URL or a filename without converting + and /
  • ⚠Generating once and reusing the value for several services or environments

Output length by command

CommandRandom bitsOutputTypical use
openssl rand -hex 1612832 hex charsRAILS_MASTER_KEY, short tokens
openssl rand -base64 1612824 charsCSRF tokens, nonces
openssl rand -base64 3225644 charsAUTH_SECRET, NEXTAUTH_SECRET, JWT secrets
openssl rand -hex 3225664 hex charsAPI keys, webhook secrets, AES-256 keys
openssl rand -base64 4838464 charsHS384 JWT secrets
openssl rand -base64 6451288 chars (2 lines in OpenSSL)HS512 JWT secrets

Base64 length is 4 × ceil(N / 3) characters; hex is always 2 × N. More bytes than the algorithm needs do not add security, so 32 bytes covers almost every secret in a .env.

Writing the value into .env from a script

# OpenSSL wraps base64 after 64 characters: strip newlines for long values
echo "AUTH_SECRET=$(openssl rand -base64 32)" >> .env
echo "JWT_SECRET=$(openssl rand -base64 64 | tr -d '\n')" >> .env
echo "API_KEY=$(openssl rand -hex 32)" >> .env

# base64url (URL-safe) from base64
openssl rand -base64 32 | tr '+/' '-_' | tr -d '='

No OpenSSL? node -e "console.log(require('crypto').randomBytes(32).toString('base64'))" or python -c "import secrets,base64;print(base64.b64encode(secrets.token_bytes(32)).decode())" produce the same format. For ready-made presets per use case, see the secret generator and the JWT secret generator.

Is browser randomness as good as OpenSSL?

Yes for this purpose. crypto.getRandomValues is required by the Web Crypto specification to use a cryptographically secure generator seeded by the operating system (getrandom() on Linux, BCryptGenRandom on Windows, arc4random on macOS). openssl rand uses OpenSSL's DRBG, which seeds from the same OS source.

What matters more is where the value goes next: straight into your host's secret settings or a password manager, never into chat or a committed file. The guide .env best practices covers the rest.

Frequently asked questions

Is this as secure as running openssl rand locally?

Yes. Both use a cryptographically secure generator seeded by the operating system, and the value never leaves your browser.

When should I use -hex vs -base64?

Hex (0-9a-f) is safest in shells, URLs and config files. Base64 is shorter for the same entropy. Use whatever your framework's docs show, e.g. -base64 32 for Auth.js.

How many bytes should I generate?

32 bytes (256 bits) for secrets and keys. 16 bytes (128 bits) is enough for tokens that expire. 64 bytes only if an algorithm like HS512 asks for it.

Why does my openssl output have two lines?

OpenSSL wraps base64 at 64 characters, so anything above 48 bytes spans two lines. Remove the newline with | tr -d '\n' before writing it to a .env file.

Is the output sent to a server?

No. It is generated in your browser with crypto.getRandomValues.

Related tools

Learn more

Compare

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