Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The only supported ciphers are AES-128-CBC and AES-256-CBC #9080

Closed
mstnorris opened this issue Jun 4, 2015 · 87 comments
Closed

The only supported ciphers are AES-128-CBC and AES-256-CBC #9080

mstnorris opened this issue Jun 4, 2015 · 87 comments

Comments

@mstnorris
Copy link

@GrahamCampbell
Copy link
Member

You need to follow our upgrading guide.

@GrahamCampbell
Copy link
Member

and it looks like a Symfony component was removed that handles the decoding.

No?

@mstnorris
Copy link
Author

@GrahamCampbell Thanks but I don't have a 'cipher' key in my config/app.php. I've added it and it works, however I didn't remove it so the upgrade guide is misleading.

@andrewtweber
Copy link

In config/app.php I have

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

In my .env file I have APP_KEY of length 32 characters. I am getting the same error as above.
I also tried php artisan key:generate, which created a new key of length 16 characters, but it still has the same error message.

@GrahamCampbell
Copy link
Member

You likely need to clear the config cache.

@andrewtweber
Copy link

Ok sorry.. I think artisan config:clear may have done the trick... it was looking for the wrong env variable in another location, so the key was an empty string. Rookie mistake. Thanks.

@shakirblouch
Copy link

run this command

php artisan key:generate

and the clear config cache using

php artisan config:clear

will solve this problem

@GrahamCampbell
Copy link
Member

You should run confg:cache rather than clear.

@gp187
Copy link

gp187 commented Aug 25, 2016

The problem I encountered is in config/app.php as a default after key:generate this was the result.
'key' => env('32charshere'),

The problem is the key is empty for config and doesn't get registered, that's why the error

change to
'key' => '32charshere',

and works

@zhekaus
Copy link

zhekaus commented Aug 31, 2016

Try run 'php artisan key:generate' again if you have such an issue.

@kimpastro
Copy link

In my case, the composer do not generate .env file. So i've created it, then execute key:generate and it works!

@martinacostadev
Copy link

In my case, I just run the command php artisan config:clear. Thank you!

@mdkieran
Copy link

mdkieran commented Oct 9, 2016

I get this error if I refresh the page too quickly, otherwise it works fine.

@GrahamCampbell
Copy link
Member

I get this error if I refresh the page too quickly

That's because you forgot to cache the config.

@kristianvanessen
Copy link

use in command copy .env.example .env because you are missing the .env file. at least it worked for me.
and then use the generate key command.

@taksunil
Copy link

taksunil commented Oct 19, 2016

Steps to solve this problem.

  1. Create .env file using this command (copy .env.example .env)
  2. Run command (php artisan key:generate)

@karthigamahe
Copy link

Hi i m having the error while i running laravel.

RuntimeException in compiled.php line 13231: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.

@crisshnangularjs
Copy link

  1. php artisan key:generate
  2. the key which is generated, add that to your env file as APP_KEY = [generated_key]

@lawalstephen
Copy link

In my own case the following was what worked

  1. ensure you have .env file if not rename the .env.example to .env
  2. run the command php artisan key:generate

@mrsimonbennett
Copy link
Contributor

If you get this error and using artisan serve, once you fix the .env issue restart the process

@tublitzed
Copy link

tublitzed commented Nov 12, 2016

using $_ENV as a default in the event that the .env file hasn't been loaded yet fixed it for me:

'key' => env('APP_KEY', $_ENV['APP_KEY'])

@kolczu
Copy link

kolczu commented Dec 1, 2016

php artisan key:generate

@alftonic
Copy link

alftonic commented Dec 9, 2016

Edit and Delete modal window its come good, but the action it's not working... thank you on advance!

@mehrancodes
Copy link

For me, adding a new .env.testing file and running phpunit cause to this error:

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

@ShermanTsang
Copy link

Thank u and it's work!

@alftonic
Copy link

alftonic commented Dec 30, 2016 via email

@knuks
Copy link

knuks commented Jan 11, 2017

thank you all 100% working properly

@alftonic
Copy link

alftonic commented Jan 11, 2017 via email

@devcircus
Copy link
Contributor

Cache your configuration and don't use env outside your config files. Shouldn't use env in production except from config.

@aluferraz
Copy link

aluferraz commented Jun 18, 2017

Ok, I see that doing config:cache in a Laravel Application solves the problem, but in a Lumen Application the .env file seems to be the only way:

https://lumen.laravel.com/docs/5.4/configuration

There is no "config caching".. I've even tried to copy the config:cache artisan command, but the cached file has no effect ... Lumen is always trying to access the .env file..

Any ideas ?

@tomiwatech
Copy link

I was using 'key' => env('Wd8ixPMi0t89o+bCZHkjQvL8ljkWSLwJLPlhEArWick') instead of
'key' => env('APP_KEY','Wd8ixPMi0t89o+bCZHkjQvL8ljkWSLwJLPlhEArWick'). so using
'key' => env('APP_KEY','Wd8ixPMi0t89o+bCZHkjQvL8ljkWSLwJLPlhEArWick') finished the job for me

Besides this guide demystified my installation process
https://tecadmin.net/install-laravel-framework-on-ubuntu/#

@congjie
Copy link

congjie commented Jun 27, 2017

php artisan key:generate then restart php artisan ser

@lloricode
Copy link
Contributor

work's fine, Thanks

language: php

php:
  - 5.6

before_script:
  - cp .env.travis .env
  - mysql -e 'create database homestead_test;'
  - composer self-update
  - composer install --no-interaction
  - php artisan migrate
  - php artisan key:generate
  - php artisan config:clear
  - php artisan config:cache

# script:
# - phpunit

config

@LF-DevJourney
Copy link

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

I solve this my cp ./.env /var/www/market

@morshud
Copy link

morshud commented Aug 20, 2017

i have the same issue but i try
php artisan key:generate
and resart your php artisan serve
then it works

@pwaring
Copy link

pwaring commented Aug 23, 2017

Three things I've noticed that are bugs in this behaviour and took me a while to work out:

  1. php artisan key:generate will say that it has set the application key successfully even if it hasn't.
  2. You must have a line APP_KEY= in your .env - key:generate won't add this for you.
  3. key:generate will append to, rather than replace, APP_KEY. If you run key:generate multiple times, you'll end up with a long key that doesn't work.

@mmsa
Copy link

mmsa commented Aug 23, 2017

  1. run php artisan key:generate if you received
    [ErrorException] file_get_contents(/.env): failed to op en stream: No such file or directory
    You need to rename .env.example to .env in the application root

@svengit
Copy link

svengit commented Aug 31, 2017

This is still an issue. Fresh install from yesterday (Laravel 5.4).
I cannot get it to work with the key in .env. It has to be either in config/app.php or the config has to be cached, both no viable solutions.

Edit: I feel a bit dumb now. .env was not readable. Might be good to produce at least a warning when this happens 'Warning: .env exists but cannot be read' or something like that

@JonMadVal
Copy link

Hi i changed the value of the 'key' parameter in app.php for the value of the APP_KEY in the .env file like this:
OLD: 'key' =>'env('APP_KEY')'
NEW : 'key' =>'base64:ybs4GNU0vR4bmJVAJx+c82nFIpbJ3cHop4dwcS3QTe*(',

Thats work for me.

@rs-sliske
Copy link

@JonMadVal while that technically works, that isnt really a secure solution

one of the reasons that key, along with database/service credentials are in the .env file is that they shouldnt be included in your source control, which by default at least, config files are, .env is not

it would be far better to look into why it failed to read the value from .env, which is likely to either be a file permissions issue, or a caching issue (try running artisan config:clear)

@JonMadVal
Copy link

@rs-sliske for sure is not a secure solution but any of the above solutions works for me, i tried changed the permissions file, i executed the config:clear command, re-build the key but does't works.

maybe the weekend i can work on it and looks for the optimal solution.

If you have some idea to tried i'll glad to know it, i'm running laravel fedora.

Thanks

@vincurekf
Copy link

I have the same issue, on Laravel 5.4.*, I am getting:

local.ERROR: exception 'RuntimeException' with message 'The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.'

and

local.ERROR: exception 'PDOException' with message 'SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)'

Putting APP_KEY and DB_* values directly in config/app.php and config/database.php solved the issue, but I don't think this is the best solution.

I have .env file with permissions 0744 and all variables mentioned above set correctly.

Other than setting values directly in config files, I've tried all solutions suggested above:

php artisan key:generate
php artisan config:clear

with no permanent effect, the error pops up randomly, most with ajax requests (eg. uploading multiple files, where 3 of 4 files are uploaded, the 4th returns one of the errors)

When I try config:cache after key:generate I get:

local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Cannot redeclare class App\__'

One think to notice, I am running these commands from a route:

Route::get('/clear-fix', function() {
    $this->middleware('auth');
    $exitCode = Artisan::call('key:generate');
    $exitCode = $exitCode == 0 ? Artisan::call('config:clear') : $exitCode;
    $exitCode = $exitCode == 0 ? Artisan::call('config:cache') : $exitCode;
    return $exitCode;
});

@kennblvnp
Copy link

Mine works using this:

  1. composer update
  2. php artisan key:generate
  3. php artisan config:clear
  4. php artisan config:cache

@PeiyuanQi
Copy link

PeiyuanQi commented Mar 26, 2018

I think the cause of the problem is there is no proper key cached.
In my situation, I solved it by performing the following procedures:
If you have ignored the .env file, which you should, then just do the following things:

  1. Make sure you have .env, create one by cp .env.example .env
  2. Generate new key by php artisan key:generate
  3. Clear cache and cache new key by php artisan config:cache

Hope it works for you.

@TomRosenbloom
Copy link

Here is a simplistic explanation of how this Laravel/Heroku API key business works, according to my understanding and how I managed to get it working:

  • When you create a new laravel application, an APP_KEY constant is created in .env
  • Your Heroku deployment of the Laravel app must have the same key
  • You can set/update the key that Heroku has via the Heroku dashboard, OR you can set it via the command line with 'heroku config:set APP_KEY=...'
  • The form of the key is 'base64:' followed by 43 characters and an equals sign (I think this is right, anyway the important thing is that you include the whole thing - initially I mistakenly left off the 'base64:' part)

I found the official documentation to be unclear. You are told to use artisan to generate a key, but my understanding is that (1) you don't need to do this because a key will have been created (by Composer) during creation of the laravel application (2) if you do use artisan to generate a key you would need to manually insert this key into the laravel .env file as well as supplying it to Heroku since it will be different from the one you currently have in .env (perhaps in some environments the artisan generate command updates .env?)

@devcircus
Copy link
Contributor

The .env file is updated every time you run the command. The only time the key is automatically created for you is when you run "laravel new" to create an app. Anytime you clone a repo or begin a project another way, you'll need to run that command. Then, no matter what hosting service you use, you'll have to set the key on the server to match the key that was generated.

@TomRosenbloom
Copy link

That makes sense, and that's how I would have expected it to work, but on my (Windows) local machine running the command doesn't update the .env file.

@Cholowao
Copy link

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

@hu-qi
Copy link

hu-qi commented Jun 26, 2018

The method is correct as @shakirblouch ,thanks!
run

php artisan key:generate

then run

php artisan config:clear

my version
php 5.6.36
laravel 5.3.*
window 10

@umerchohan8
Copy link

In my case
php artisan key:generate
php artisan config:clear

After that i killed the old server and run again
php artisan serve

Because you should restart server after any change in .env file.

@Saif-hub24
Copy link

Following commands worked for me
php artisan key:generate
php artisan config:clear

@wonbin2011
Copy link

add value to APP_KEY of .env file , like this:
APP_KEY=base64:jdsdaKgJLr9CmxOBgVfJaTNWuBPkmTp24NtAe6rWDmY=

@marceloagil
Copy link

In my case, I'v tried everything above and didn't worked. My app was running fine until it crashed and I'v found that env file was not being readed.

I was running app with php artisan serve. I stop serve and run the commands, but no solution. I'v found that you need to keep php artisan serve running and run these commands:

php artisan config:clear
php artisan config:cache

Restart php artisan serve

Thank you jay_mizray .

@rs-sliske
Copy link

i believe php artisan serve is only intended to be used for development.

not for production.

@pablorsk
Copy link
Contributor

pablorsk commented Jan 25, 2019

I back to this post again and again... Can be many factors, then...

On non testing environments (production or develop, for example) environments:

  • php artisan config:clear
  • Check on config/app.php you are reading env file (like 'key' => env('APP_KEY'),)
  • Check .env file you have vale APP_KEY
  • Check if APP_KEY has the correct length (examples below)

On testing environments, also:

  • php artisan config:clear --env=testing
  • Check, if you have, .env.testing file you have vale APP_KEY and lenght.
  • Check, if you have, <env name="APP_KEY" value="xxx/> on phpunit.xml
  • Key correct length:
    • AES-128-CBC base64:fOy5GTwFhkcBrcdtCtDZKQ== or Zk95NUdUd0Zoa2NCcmNkdEN0RFpLUT09
    • AES-256-CBC base64:90jl2DpeHHRKn+no8/4Rpsg/ZemQB0PaNgSEv4kkiqw=

If the problem persists, put this before error: dd(config('app.key'));, check if is your desired app_key. sometimes its a problem with cache, or a missing configuration.

@laravel laravel locked and limited conversation to collaborators Jan 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests