Laravel APP_KEY generator

Get a Laravel application key when you can't run artisan: 32 random bytes, Base64-encoded with the base64: prefix, as an APP_KEY= line for your .env file.

runs in your browser · nothing uploaded

loading tool…

How to use it

  1. Keep AES-256-CBC unless config/app.php sets cipher to AES-128-CBC.
  2. Copy the APP_KEY= line into your .env file.
  3. Clear the config cache if you use it: php artisan config:clear.

What key:generate does

php artisan key:generate makes random bytes of the length the cipher needs (32 for AES-256-CBC, the default) and writes them to .env as base64: followed by the Base64 encoding. The equivalent in plain PHP is 'base64:' . base64_encode(random_bytes(32)). We ran it: the key is 44 Base64 characters and decodes back to 32 bytes.

Before you replace a key

Laravel encrypts cookies, sessions and anything you store with Crypt using this key. Changing it on a live app signs everyone out and makes data encrypted with the old key unreadable. Since Laravel 11 you can list old keys in APP_PREVIOUS_KEYS so existing data can still be decrypted while you rotate.

Questions

Is the value sent to a server?

No. It is made in your browser with JavaScript and the Web Crypto API. Nothing is uploaded, logged or stored by us. For production secrets you may still prefer to generate them on the machine that uses them; the command for that is on this page.

Can I share one APP_KEY between environments?

Don't. Give local, staging and production their own keys, so a leaked development .env can't decrypt production data.

Why does my key start with base64:?

It tells Laravel to decode the rest before use. Without the prefix Laravel would treat the 44 characters as the key itself, which is the wrong length.