Better Auth Secret Generator

Generate a random BETTER_AUTH_SECRET in one click and copy it as a ready-to-paste .env line. Pick 32, 64 or 128 bytes. Runs locally, nothing is uploaded.
.env

Store this secret securely. Do not commit it to Git!
See also Better Auth documentation


Other ways to generate BETTER_AUTH_SECRET

OpenSSL CLI
Generate a Base64-encoded 32-byte secret with OpenSSL:
openssl rand -base64 32Generate with OpenSSL Rand Online
Better Auth CLI
Generate BETTER_AUTH_SECRET with the Better Auth CLI:
npx auth@latest secret

Other Coding Tools


Better Auth Secret Generator - Create BETTER_AUTH_SECRET

Generate a secure, random BETTER_AUTH_SECRET for your Better Auth configuration and copy it as a ready-to-paste .env line. The secret is created with your browser's cryptographic random number generator, so it never leaves your device.

What is BETTER_AUTH_SECRET?

BETTER_AUTH_SECRET is the environment variable Better Auth uses as the key for encrypting, signing, and hashing data such as session cookies and tokens. Better Auth also accepts AUTH_SECRET as a fallback. Without either variable, development uses a built-in default secret, but production throws an error, so every deployed app needs its own random value.

How do I generate a Better Auth secret?

Choose a length and the tool instantly shows a new secret as BETTER_AUTH_SECRET=.... Click the copy button and paste the line into your .env file, or use the refresh button to generate another value. The bytes come from crypto.getRandomValues(), the cryptographically secure random source browsers use for keys and tokens.

How long should BETTER_AUTH_SECRET be?

Better Auth requires a secret of at least 32 characters. The Better Auth docs suggest 32 random bytes (openssl rand -base64 32), which gives a 44-character base64 string with 256 bits of entropy. This tool defaults to 64 bytes (88 characters, 512 bits), and you can pick 32, 128, or a custom number of bytes. 32 bytes is already far beyond what can be brute-forced.

Why is the secret base64-encoded?

Raw random bytes can't be stored safely in a text file, so the tool encodes them as base64. The result only contains letters, digits, +, /, and =, which work in any .env file. Better Auth uses the string as it is, so you don't need to decode it.

Is this secret generator secure?

Yes. The secret is generated locally with the Web Crypto API and is never sent to a server, logged, or stored by giga.tools. Each click on the refresh button creates a completely new value.

Where do I put BETTER_AUTH_SECRET?

Paste the copied line into the .env file of your server project, or add the value to your hosting provider's environment variables or secrets manager. Never commit it to Git or expose it to client-side code, and give development, staging, and production their own secrets.

What are alternatives to this online generator?

In a terminal, run openssl rand -base64 32, or use the Better Auth CLI with npx auth@latest secret. The older @better-auth/cli package is deprecated. This browser tool is handy when you don't have OpenSSL or Node.js at hand, or want a different length. For passwords or other random strings, use the Password Generator.

Can I change BETTER_AUTH_SECRET later?

Yes, but replacing the secret outright invalidates existing sessions and anything Better Auth encrypted with the old key, so users have to sign in again. To rotate without that disruption, Better Auth supports versioned secrets through the secrets option or the BETTER_AUTH_SECRETS environment variable: the newest key encrypts new data while older keys stay available for decryption. The Better Auth options reference explains the details.

What happens if I use a weak secret?

A weak or predictable secret, such as a password, a common phrase, or a short string, can be guessed or brute-forced. Attackers could then forge session tokens or decrypt protected data. Always create the secret with a cryptographically secure generator like this tool or OpenSSL.


This tool is not part of the Better Auth brand.

Navigator

Quickly navigate to any tool