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

南楼画角 提交于 2019-12-17 10:33:07

问题


I installed a new fresh copy of laravel 5.3 using composer but I keep 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',


回答1:


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



回答2:


Run this commands on your terminal:

php artisan config:clear
then
php artisan config:cache




回答3:


Run php artisan key:generate.

Do php artisan config:clear,

Then php artisan config:cache

And things will start working!




回答4:


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.




回答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.




回答6:


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.




回答7:


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.




回答8:


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.




回答9:


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




回答10:


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.




回答11:


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.



来源:https://stackoverflow.com/questions/39693312/the-only-supported-ciphers-are-aes-128-cbc-and-aes-256-cbc-with-the-correct-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!