Laravel APP_KEY generator

A fresh encryption key in the exact format php artisan key:generate writes to your .env, for when you are setting up a server, a CI pipeline or a container and have no artisan at hand.

Your key

Generated with crypto.getRandomValues in this tab. The key never leaves your browser: no request is made when you generate or copy it, and nothing about it is tracked. Prefer to see it for yourself? Open your browser's network tab and press Regenerate.

Check an existing key

Getting "Unsupported cipher or incorrect key length"? Paste the value (it stays in your browser) to see whether its length matches the cipher selected above.

How Laravel builds the key

key:generate asks Encrypter::generateKey() for random_bytes() of the length your cipher needs, base64-encodes them and adds the base64: prefix. When the app boots, the encryption service provider strips that prefix and decodes the rest, so what the encrypter actually receives is raw bytes. This page does the same with your browser's cryptographically secure random generator: 32 bytes for AES-256 (44 characters of base64), 16 bytes for AES-128 (24 characters).

Laravel supports four ciphers: AES-128-CBC, AES-256-CBC, AES-128-GCM and AES-256-GCM. A fresh application ships with 'cipher' => 'AES-256-CBC' in config/app.php. The key length has to match that setting exactly; a 16-byte key with an AES-256 cipher throws RuntimeException: Unsupported cipher or incorrect key length, and an empty APP_KEY throws MissingAppKeyException ("No application encryption key has been specified").

# .env
APP_KEY=base64:

# Or, with artisan available, print one without touching .env:
php artisan key:generate --show

What APP_KEY protects, and what it does not

  • Cookies. The EncryptCookies middleware encrypts every cookie that is not on its exception list, including the session cookie and the "remember me" cookie.
  • Anything you encrypt yourself with Crypt::encryptString() or encrypt(), and Eloquent attributes cast as encrypted, encrypted:array and friends.
  • Queued jobs that implement ShouldBeEncrypted, and the session payload itself when SESSION_ENCRYPT=true.
  • Signed URLs. URL::signedRoute() and temporarySignedRoute() sign with an HMAC keyed by app.key.
  • Not password hashes. Hash::make() uses bcrypt or Argon2 with a per-hash salt and never reads APP_KEY, so changing the key does not lock anyone out of their password.

What happens when you change it

With a new key and nothing else, data encrypted under the old key can no longer be read. Existing session cookies fail to decrypt, so every user is logged out. Encrypted model attributes throw DecryptException: The MAC is invalid when you access them. Signed links you already emailed stop validating, and encrypted jobs waiting in the queue fail.

To rotate without that breakage, move the old key to APP_PREVIOUS_KEYS, a comma-separated list that config/app.php reads into app.previous_keys. Laravel always encrypts and signs with the current key, but when decrypting it tries the current key first and then each previous one, and signed URLs and cookies are accepted if any of the keys matches.

APP_KEY=base64:<new key from this page>
APP_PREVIOUS_KEYS=base64:<the key you are replacing>

Values only get re-encrypted with the new key when they are written again, so if you want to drop the old key eventually, re-save your encrypted columns first.

Keep it out of git

Anyone holding your key can decrypt your cookies and encrypted columns and forge signed URLs that your app will accept. That is why .env is in Laravel's default .gitignore and .env.example ships with an empty APP_KEY=. Give each environment its own key, store production's in your host's secret manager or environment settings, and if a key was ever committed, treat it as leaked and rotate it as described above.

Setting up a new Laravel app?

Once the key is in place, the next things to configure are usually locale and translations. Our getting started guide and the five-minute setup walkthrough cover adding live translations, the locale code lookup tells you which folder name to give each language, and the other free tools test plurals, find hardcoded strings and convert lang files.

Frequently asked questions

Is it safe to generate an APP_KEY online?

With this page, yes: the key is created by your browser's crypto.getRandomValues, the same kind of cryptographically secure generator PHP's random_bytes() uses, and it is never sent anywhere. Generating or copying a key makes no network request, which you can confirm in your browser's developer tools.

Is the key identical in format to php artisan key:generate?

Yes. key:generate base64-encodes random bytes of the length your cipher needs and prefixes them with base64:. For the default AES-256-CBC that is 32 bytes, a 44-character base64 string; AES-128 ciphers use 16 bytes. Running php artisan key:generate --show prints a key in the same format without writing to .env.

Will changing APP_KEY log out my users?

Yes, unless you keep the old key in APP_PREVIOUS_KEYS. Session and remember-me cookies are encrypted with the key, so with a new key they can no longer be read and users have to sign in again. Encrypted model attributes and already-issued signed URLs are affected the same way.

Does APP_KEY affect password hashes?

No. Hash::make() uses bcrypt or Argon2 with its own salt and never reads APP_KEY, so passwords keep working after you change the key. What breaks is data that was encrypted, not hashed.

Why do I get "Unsupported cipher or incorrect key length"?

The decoded key does not have the length the configured cipher needs: 32 bytes for AES-256-CBC and AES-256-GCM, 16 bytes for the AES-128 variants. The usual causes are a missing base64: prefix, a truncated value, or a key generated for a different cipher. Paste it into the checker on this page to see its length.

Useful? Link to it

The tool is free and stays free. Paste this into a README, a wiki page or a forum answer.

<a href="https://langsyncer.com/tools/laravel-app-key-generator">Laravel APP_KEY Generator</a> by LangSyncer

Ship translations without redeploying

Your key is set; now make the app speak your users' languages. LangSyncer imports your Laravel lang files, translates the missing keys with AI and publishes changes to production in seconds.

We'd like to use analytics and marketing cookies to understand how the site is used. They stay off unless you accept them. Cookie Policy