Laravel app key problem:The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths

Laravel app key problem:The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths

When setting up a laravel project I came across this problem:

Google search for this problem and I solved it by generating APP_key parameter.

This problem happens when the APP_KEY parameter in the .env file is set to a useless string. Usually APP_key should be generated automatically by running php artisan key:generate command.

Also I’d like to mension that there’re parameters in config/app.php related with this problem. If php artisan key:generate does not solve your prolbem, you shold check these parameters as well.

/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| This key is used by the Illuminate encrypter service and should be set
| to a random, 32 character string, otherwise these encrypted strings
| will not be safe. Please do this before deploying an application!
|
 */

'key' => env('APP_KEY', 'SomeRandomString'),

'cipher' => 'AES-256-CBC',

Make sure that APP_KEY matches cipher configuration values. Check the supported() function below.

    /**
     * Determine if the given key and cipher combination is valid.
     *
     * @param  string  $key
     * @param  string  $cipher
     * @return bool
     */
    public static function supported($key, $cipher)
    {
        $length = mb_strlen($key, '8bit');

        return ($cipher === 'AES-128-CBC' && $length === 16) ||
               ($cipher === 'AES-256-CBC' && $length === 32);
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.