The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths. laravel 5.3

Laravel 5ConfigurationInstallation

Laravel 5 Problem Overview


I installed a new fresh copy of Laravel 5.3 using composer but I'm getting this error:

> The only supported ciphers are AES-128-CBC and AES-256-CBC with the > correct key lengths. Even though my app.php file in config directory specify
> 'cipher' => 'AES-128-CBC'

Laravel 5 Solutions


Solution 1 - Laravel 5

You need to have .env on your appication folder then run:

$ php artisan key:generate

If you don't have .env copy from .env.example:

$ cp .env.example .env

Solution 2 - Laravel 5

Run php artisan key:generate.

Do php artisan config:clear,

Then php artisan config:cache

And things will start working!

Solution 3 - Laravel 5

Just remove APP_KEY value from .env file and run this commands again :

php artisan key:generate
php artisan config:cache

Done.

Solution 4 - Laravel 5

Run this commands on your terminal:

php artisan config:clear
then
php artisan config:cache

Solution 5 - Laravel 5

Ok, this has basically already been answered, but I found a couple caveats that had be consternated, or constipated, one of those two...

First, as has already been said, you should ensure you have a valid .env file which you can accomplish in the terminal by copying the existing .env.example file as such:

$ cp .env.example .env

Then, generate your application Key

$ php artisan key:generate

Once this is done, make sure to open your .env file and ensure that the APP_KEY line looks correct - this is where my consternation came from:

APP_KEY=base64:MsUJo+qAhIVGPx52r1mbxCYn5YbWtCx8FQ7pTaHEvRo=base64:Ign7MpdXw4FMI5ai7SXXiU2vbraqhyEK1NniKPNJKGY=

You'll notice that the key length is wrong, it for some unknown reason (probably from running key:generate multiple times) has two base64= keys in there. Removing one is the fix to the problems I was having and this appears to be an Artisan/Laravel bug.

Hope this answer helps anyone who may be struggling with the same problems or annoying bug.

Solution 6 - Laravel 5

If you are running a Laravel project for the first time in that machine make sure you have the necessary requirements. Open your CMD/Terminal in your project directory or

cd to/your/project/dir

Give this command again:

composer update

Change your .env.example to .env and make necessary changes in that file especially database configurations to avoid db error. Then

php artisan key:generate

This solves this AES cipher key length problem every time I create a Laravel project or clone it from git.

Solution 7 - Laravel 5

in .env file give this key and you are done

APP_KEY=ABCDEF123ERD456EABCDEF123ERD456E

Still not working?

If you are working from cli, reboot the server and it will.

Want explanation?

ok, as the error message says:

> The only supported ciphers are AES-128-CBC and AES-256-CBC with the > correct key lengths.

Key length for AES-128-CBC is 16 characters e.g ABCDEF123ERD456E

Key length for AES-256-CBC is 32 characters e.g ABCDEF123ERD456EABCDEF123ERD456E

Make sure in config/app.php the cipher is set to the appropriate cipher like the two above and the key is pointing to the .env file APP_KEY variable. My app has the AES-256-CBC cipher set, so i gave it the 32 characters key like APP_KEY=ABCDEF123ERD456EABCDEF123ERD456E and everything worked just fine after that.

Solution 8 - Laravel 5

Follow These Steps:

Step 1: Make sure you have .env file in your application.If not run this command cp .env.example .env

Step 2: Now run following command ( php artisan key:generate ) to generate a key and it will get saved in .env file automatically.

Step 3: Run php artisan config:cache if you want to cache the configurtration Or php artisan config:clear

Hopefully it will fix everything.

Solution 9 - Laravel 5

Check your .env file if APP_KEY is not set, it is the issue, Now run php artisan key:generate then run php artisan config:cache

it will set an APP_KEY key in your .env file.

If APP_KEY is already set run the same commands. It will update this key.

Solution 10 - Laravel 5

For laravel version 5.4 PHP 7.4

  1. To solve run this command

php artisan key:generate

This will set a value for APP_KEY= in your .env file

something like this: APP_KEY=base64:trp5LQ9/TW85+17o0T7F0bZ/Ca1J9cIMgvyNIYl0k/g=

  1. Clean cache to get everything working again with the following commands:

php artisan config:clear

then php artisan config:cache

Hope this helps.

Solution 11 - Laravel 5

I also had this issue. I check my environment variable value for "APP_KEY" using echo $APP_KEY For me it was "lumen" which was set for another lumen project and that's why it was not working.

I updated "APP_KEY" value using export APP_KEY=[you app_key value from .env file] and cleared cache php artisan config:cache and it worked for me.

Solution 12 - Laravel 5

Another thing to just check is that your .env file is in the www-data group (or httpd or whatever your web server group is) and that the group has read permission.

On linux my permissions looked like this when I got this error: -rw-rw-r-- 1 kevin kevin 618 Mar 16 09:32 .env I then just removed read permission for all and removed write permission for group. chmod 640 .env Then I changed the group to www-data chown kevin:www-data .env My permissions now look like this: -rw-r----- 1 kevin www-data 516 Mar 16 09:35 .env

Solution 13 - Laravel 5

If the artisan command doesn't work and you get the same error in the command line, that means composer didn't do a good job at getting all the files, you should delete the vendor folder and run composer update again.

Solution 14 - Laravel 5

If you newly create a laravel project with command like composer create-project --prefer-dist laravel/laravel market and deploy the new repo to the application path with cp command you may get this issue.

I use laravel 5.4

roofe@www:~/market$ php artisan --version
Laravel Framework 5.4.33

When you create the laravel project, you can see the the logs that create the key like this:

> Generating autoload files > > Illuminate\Foundation\ComposerScripts::postUpdate > > php artisan optimize Generating optimized class loader The compiled services file has been removed. > > php artisan key:generate Application key [base64:exxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/k=] set successfully.

By default the key config in the config/app.php is as follows, it use AES-256-CBC and the generated key when creating the project is stored in the .env file. If you use command like cp -r ./* /var/www/market/ the .env file will not be moved to the application path.

> /* > |-------------------------------------------------------------------------- > | 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'), > > 'cipher' => 'AES-256-CBC',

When I chage my deploy command to cp -r ./* ./.env /var/www/market/, this issue gone.

You also can refer to this github issue.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEmmanuel MarikiView Question on Stackoverflow
Solution 1 - Laravel 5Mugoma J. OkombaView Answer on Stackoverflow
Solution 2 - Laravel 5Cengkuru MichaelView Answer on Stackoverflow
Solution 3 - Laravel 5Amir KaftariView Answer on Stackoverflow
Solution 4 - Laravel 5LeeView Answer on Stackoverflow
Solution 5 - Laravel 5RottinghamView Answer on Stackoverflow
Solution 6 - Laravel 5Ashfak Md ShibliView Answer on Stackoverflow
Solution 7 - Laravel 5f_iView Answer on Stackoverflow
Solution 8 - Laravel 5PHP Worm...View Answer on Stackoverflow
Solution 9 - Laravel 5Imad UllahView Answer on Stackoverflow
Solution 10 - Laravel 5Oscar GallardoView Answer on Stackoverflow
Solution 11 - Laravel 5Rakesh SadakaView Answer on Stackoverflow
Solution 12 - Laravel 5Kevin van ZylView Answer on Stackoverflow
Solution 13 - Laravel 5user2962785View Answer on Stackoverflow
Solution 14 - Laravel 5LF00View Answer on Stackoverflow