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

@mstnorris mstnorris commented Jun 4, 2015

@GrahamCampbell
Copy link
Member

@GrahamCampbell GrahamCampbell commented Jun 4, 2015

You need to follow our upgrading guide.

@GrahamCampbell
Copy link
Member

@GrahamCampbell GrahamCampbell commented Jun 4, 2015

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

No?

@mstnorris
Copy link
Author

@mstnorris mstnorris commented Jun 4, 2015

@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

@andrewtweber andrewtweber commented Jul 14, 2015

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

@GrahamCampbell GrahamCampbell commented Jul 14, 2015

You likely need to clear the config cache.

@andrewtweber
Copy link

@andrewtweber andrewtweber commented Jul 14, 2015

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

@shakirblouch shakirblouch commented May 27, 2016

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

@GrahamCampbell GrahamCampbell commented May 27, 2016

You should run confg:cache rather than clear.

@gp187
Copy link

@gp187 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 zhekaus commented Aug 31, 2016

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

@kimpastro
Copy link

@kimpastro kimpastro commented Sep 6, 2016

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

@kaizendevar
Copy link

@kaizendevar kaizendevar commented Sep 21, 2016

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

@mdkieran
Copy link

@mdkieran mdkieran commented Oct 9, 2016

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

@GrahamCampbell
Copy link
Member

@GrahamCampbell GrahamCampbell commented Oct 9, 2016

I get this error if I refresh the page too quickly

That's because you forgot to cache the config.

@kristianvanessen
Copy link

@kristianvanessen kristianvanessen commented Oct 13, 2016

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 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

@karthigamahe karthigamahe commented Oct 19, 2016

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

@crisshnangularjs crisshnangularjs commented Oct 21, 2016

  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

@lawalstephen lawalstephen commented Oct 25, 2016

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

@mrsimonbennett mrsimonbennett commented Nov 1, 2016

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

@tublitzed
Copy link

@tublitzed 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 kolczu commented Dec 1, 2016

php artisan key:generate

@alftonic
Copy link

@alftonic 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

@mehrancodes mehrancodes commented Dec 14, 2016

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.
@ShareManT
Copy link

@ShareManT ShareManT commented Dec 30, 2016

Thank u and it's work!

@alftonic
Copy link

@alftonic alftonic commented Dec 30, 2016

@knuks
Copy link

@knuks knuks commented Jan 11, 2017

thank you all 100% working properly

@alftonic
Copy link

@alftonic alftonic commented Jan 11, 2017

@aluferraz
Copy link

@aluferraz 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

@tomiwatech tomiwatech commented Jun 22, 2017

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 congjie commented Jun 27, 2017

php artisan key:generate then restart php artisan ser

@lloricode
Copy link
Contributor

@lloricode lloricode commented Jul 7, 2017

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

@KrisRoofe
Copy link

@KrisRoofe KrisRoofe commented Aug 17, 2017

@morshud
Copy link

@morshud 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

Odd-Tablet pushed a commit to Odd-Tablet/Laravel-Test that referenced this issue Aug 21, 2017
@pwaring
Copy link

@pwaring 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 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 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

@JonMadVal JonMadVal commented Sep 14, 2017

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

@rs-sliske rs-sliske commented Sep 14, 2017

@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

@JonMadVal JonMadVal commented Sep 14, 2017

@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

@vincurekf vincurekf commented Nov 15, 2017

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

@kennblvnp kennblvnp commented Jan 8, 2018

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 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

@TomRosenbloom TomRosenbloom commented Apr 20, 2018

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

@devcircus devcircus commented Apr 20, 2018

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

@TomRosenbloom TomRosenbloom commented Apr 20, 2018

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

@Cholowao Cholowao commented May 10, 2018

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 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

@umerchohan8 umerchohan8 commented Sep 28, 2018

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.

@saifrehman15
Copy link

@saifrehman15 saifrehman15 commented Oct 22, 2018

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

@wonbin2011
Copy link

@wonbin2011 wonbin2011 commented Jan 6, 2019

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

@marceloagil
Copy link

@marceloagil marceloagil commented Jan 14, 2019

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

@rs-sliske rs-sliske commented Jan 16, 2019

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

not for production.

@pablorsk
Copy link
Contributor

@pablorsk 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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.