Free · runs in your browser

Laravel App Key Generator

Laravel App Key Generator. Click generate to create a ready-to-use Laravel APP_KEY for your .env file. The free django secret key generator is completely free to use, with no rate limits, watermarks, or hidden restrictions.

Your values

Generate 1 to 100 keys at once, e.g. one per environment (development, staging, production).

On: the key starts with base64: and pastes straight into .env. Off: the raw Base64 string only.

Result

Laravel app key
—
.env line
—
All generated keys (copy)
—
Format
—
Cipher
—
Key length
—
Estimated entropy
—
Strength
—
Average time to brute force at 1 million guesses per second
—
Average time to brute force at 1 trillion guesses per second
—
Random source
—
  • No account, no logging
  • Open formulas explained below
  • Works offline once loaded

Need a fresh secret for a new project and don't have PHP handy? This Laravel app key generator builds a random key in your browser, and you can copy it straight into your .env file. Every key is a 32-byte, base64-encoded string that follows the same format Laravel's own AES-256-CBC encryption expects, so a cryptographically secure value is one click away.

Laravel App Key Generator: Create a Secure APP_KEY

An app key is the single secret your application uses to protect everything it encrypts, from sensitive data in cookies to signed links. The generator produces it by pulling 32 random bytes from a cryptographically secure source and encoding them as text, so the result is safe to paste into configuration and impossible to guess. You click the generate button, copy the value, and set it as APP_KEY in your environment. The rsa key pair generator gives you a copy-ready result instantly, with no account required.

The finished value always has the shape base64: followed by 44 characters. For example, a fresh run produced base64:8BiXp7UybECc9ihu9lnDdl9eys73TgHdMUDD5CeI/48=. Never reuse that sample: every project deserves its own unique key, and anything published on a web page is no longer a secret.

Why 32 bytes and AES-256-CBC

Laravel's default cipher is AES-256-CBC, which needs a key of exactly 32 bytes, or 256 bits. Thirty-one bytes fails and thirty-three bytes fails too, so the length is not a style choice. The text form is longer than the raw key because base64 turns every 3 bytes into 4 characters:

$$\text{characters} = 4 \times \left\lceil \frac{32}{3} \right\rceil = 44$$

That count includes one trailing = padding character. The raw key space is \(2^{256}\), roughly \(1.16 \times 10^{77}\) possible values, which is why 256-bit entropy cannot be brute forced.

The base64: prefix explained

The base64: prefix tells Laravel to decode the text back into raw bytes before it builds the encrypter. Leave it off and Laravel treats your string as the literal key, which usually has the wrong length. The generator includes the prefix by default, because that is the format that works when you paste straight into the .env file.

What a Laravel Application Key Does

The Laravel application key sits behind every feature that must stay private and tamper-proof. Laravel's encrypter uses it to encrypt values, then signs the result with a message authentication code (MAC), so nobody can alter an encrypted payload without detection. If the key is missing, the framework cannot start encrypting at all, and you see a "No application encryption key has been specified" error. You can generate an ssh key pair in seconds with a free tool that runs entirely in your browser.

Encryption, sessions and cookies

Every cookie that leaves your server, including the session cookie, is encrypted with this key. Encryption keeps those values unreadable in the browser, and the MAC blocks tampering. The same key protects anything you pass through the Crypt facade with encryptString, such as a stored third-party token or an encrypted database column.

CSRF, signed URLs and password reset tokens

Beyond encryption, the key signs other values. CSRF tokens, signed URLs and password reset tokens all depend on it. Change the key and every signed link you already emailed stops validating, which matters if you send long-lived invitation links.

What the key does not protect

  • Database passwords: your connection credentials live in separate configuration values.
  • User passwords: hashing with bcrypt or argon2 is independent of the app key.
  • Third-party API credentials: external services issue their own secrets.
  • Transport security: HTTPS and certificates are handled by your web server.

How the Laravel Encryption Key Generator Builds Your Key

This Laravel encryption key generator mirrors what the framework does internally. Laravel's Encrypter::generateKey() method asks PHP's random_bytes() for 32 random bytes, then the artisan command wraps the result with base64_encode and adds the prefix. The page does the equivalent in your browser using a CSPRNG, which is a cryptographically secure random number generator.

Because generation is client-side, the key never has to travel to a server. That is good for security on a throwaway development site, and it makes it a reasonable choice for a throwaway development site, though for a high-value production secret you may prefer the offline methods below.

Ways to generate a key locally

Ways to generate a key locally
MethodCommandNeeds
Artisan commandphp artisan key:generateA working Laravel project
OpenSSLecho "base64:$(openssl rand -base64 32)"OpenSSL on the shell
PHP CLIphp -r "echo 'base64:' . base64_encode(random_bytes(32));"PHP only, no project
New projectcomposer create-project laravel/laravelComposer, which creates a key for you

Using Your App Key in the .env File

Once you have a value, the setup takes a minute. Open the project root, find the .env file, and set the variable to your new key. Treat it like a password, since the security of every encrypted value rests on it: .env belongs in .gitignore, never in version control.

Update the env file step by step

  1. Generate a key and copy it to your clipboard.
  2. Open the .env file and replace the value, so the line reads APP_KEY=base64:your-new-key.
  3. Run php artisan config:clear so Laravel drops any stale config cache and reads the new key.
  4. Restart your queue workers and web server so every process loads the same value.

Run the artisan command instead

If your project already runs, the artisan command is the simplest option: php artisan key:generate writes a key into the file for you. Add --show to print it without writing, which is handy for remote servers or a deployment secret.

Setting APP_KEY in Docker and CI/CD

  • Docker: pass the key as an environment variable at run time instead of baking it into the image.
  • CI/CD: store the key in your pipeline's secret manager, or call an API endpoint of your own that returns a fresh one, and inject it per job.
  • Staging and development: give each environment its own unique key.
  • Self-host installs: generate the key before the first boot so users never see an error.

Laravel Key Generator Options: Bulk Generation and Multiple Keys

A single project often needs more than one secret. The bulk generation option returns several values at once, so you can prepare every environment in one pass.

Generate multiple keys for each environment

Create one for local work, one for staging, one for production and one spare for emergencies. Keeping a random key per environment means a leak from a development laptop never exposes production data. Sharing one value across them is the most common mistake, since an attacker who gets the weakest copy can decrypt data from the strongest.

Laravel APP_KEY Generator versus php artisan key:generate

Both approaches yield equivalent keys. The php artisan key:generate route is the one Laravel recommends when you have a project, while this Laravel APP_KEY generator helps when you have none yet: preparing secrets for a deployment, filling in a hosting dashboard, or doing Laravel installation on a machine without PHP. Both rely on secure random bytes, so neither is stronger.

Laravel Key Generator Walkthrough: Fixing a Staging Server Without PHP

Priya Raman is deploying a client's Laravel build to a staging VM at 10.4.17.62 from a Windows laptop with no PHP installed. The container boots, then fails on the first request with "No application encryption key has been specified." She needs a value for APP_KEY and can't run php artisan key:generate locally.

She opens this Laravel key generator, leaves the base64: prefix switched on, sets the count to 1 and clicks the generate button. The page returns a 51-character string: the 7-character prefix plus 44 characters of base64 text. She pastes it into the staging .env and, because she is cautious, checks the length from the VM's shell:

echo -n "<key without prefix>" | base64 -d | wc -c

The output is 32. That matters because Laravel's AES-256-CBC cipher requires exactly 32 bytes, which is the cipher requirement her team's runbook cites. A 31-byte paste, the typical clipboard slip, would throw an "unsupported cipher or incorrect key length" error instead.

Next she runs php artisan config:clear inside the container, since the earlier failed boot cached the empty value, and reloads the page. The login form renders, and the session cookie now arrives encrypted. Her next decision is about separation: she runs the generator again for the production host, so the 51-character staging key and the production one never match. Her last step is adding both to the team's secret manager, so the next rebuild of the 41-second Docker image reads the key from the environment instead of from the repository.

Key Rotation and APP_PREVIOUS_KEYS in Production

Changing the key on a live site has consequences. The change will invalidate every user session, and any value encrypted under the old key can no longer be decrypted. For an application in production, that can mean logged-out customers and unreadable encrypted data.

Rotating without downtime

Laravel supports graceful key rotation. Put the new key in APP_KEY and move the old one into APP_PREVIOUS_KEYS, a comma-delimited list. New values are always encrypted with the current key, while decryption tries the current key first and then every previous key until one works. Once old sessions have expired, remove the retired keys.

When you must replace the key immediately

If the secret has been compromised, it must be rotated right away. Keep the old value in APP_PREVIOUS_KEYS only as long as you need to re-encrypt stored data. Then redeploy and remove it, since a leaked key left in the list still opens everything it ever encrypted.

Common Mistakes with an APP_KEY Generator

  • Committing the key to GitHub or any public repository. Treat a leaked key as compromised and rotate it.
  • Pasting a key without the prefix, which produces the wrong length and a decryption failure.
  • Copying a key from a tutorial or an example page instead of generating your own.
  • Regenerating the key on every deployment, which invalidates sessions each time.
  • Forgetting to run config:clear after editing, so the app keeps using the cached value.

Avoid these and Laravel app key generating becomes something you do once per environment and then forget, with no loss of security. The framework's documentation on encryption is a good reference for the underlying Laravel configuration and the cipher options it supports.

Frequently Asked Questions

Why does the key start with base64:?
Laravel prefixes APP_KEY with base64: so the framework knows to decode it before use -- without that prefix, Laravel would treat the raw string itself as the key material rather than decoding it first. Always keep the prefix when copying the value into your .env file.
What does APP_KEY actually protect?
It's the root key Laravel's encrypter uses for all AES-256-CBC (or GCM) encryption and decryption calls, including encrypted cookies, signed URLs, and anything you explicitly encrypt with Laravel's Crypt facade. Losing it means losing access to anything previously encrypted with it.
Is this the same as php artisan key:generate?
Yes -- identical format and equivalent randomness, generated in your browser instead of via Artisan. php artisan key:generate additionally writes the value directly into your .env file for you; here you'll need to copy it in yourself.
What happens if I change APP_KEY on a live application?
Every previously encrypted value -- encrypted cookies, signed URLs, anything stored via Crypt::encrypt() -- becomes permanently undecryptable, and all active sessions using encrypted cookies are invalidated. Only rotate a live APP_KEY deliberately, with a plan for what depends on the old one.
Is my key sent anywhere when I generate it?
No. It's generated entirely in your browser using the Web Crypto API's cryptographically secure random number generator -- nothing is transmitted, logged, or stored.

About the author

Vinitha Pu

Founder and designer

Vinitha Pu is a graphic designer based in Palakkad, Kerala, who builds free, privacy-friendly browser tools. She studied Textile and Apparel Design at Avinashilingam University and completed a C-Tech in Graphic Design at Image Creative Education in 2025. She designs, builds and maintains the password generators, strength checkers, hash tools and security calculators on PasswordHive.

  • Content author: Vinitha Pu
  • Fact checked by: Vinitha Pu. Each tool's output is checked against official test vectors or a reference implementation, and every strength and crack-time figure against the formula it uses, before it goes live.
  • Published Updated