Support the ongoing development of Laravel.io →
Installation
Last updated 1 year ago.
0

In config\app.php change:

'cipher' => 'whatever it is',

to

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

0

I have that cipher in my app.php but it still without working

0

php artisan key:generate :)

0

I just had the same problem on a new Laravel project and levinhne's suggestion worked.

To elaborate on the cause, the default cipher in confing/app.php is "AES-256-CBC" which needs a 32 character string, but the default key is "SomeRandomString," which is only 16 characters.

So, you can either set the cipher to "AES-128-CBC" which only needs 16 characters, or generate a new 32 character string for the key. Entering "php artisan key:generate" is the simplest solution.

0

It's so strange, cause the documentation states that the key is supposed to be generated and set automatically... I wonder why that's not happening.

0

Had the same problem, "php artisan key:generate" worked well.

Maybe the docs and source should be updated, for example with "SomeRandomStringWith32Characters" which would - magically - be exactly 32 characters long and solve this problem...

Last updated 8 years ago.
0

this solved my issue:

vagrant@homestead:~/projects/diziu$ php artisan key:generate
Application key [xlhF31NeOlibJcoOW9tvZg7TkHcAZI3a] set successfully.
vagrant@homestead:~/projects/diziu$ nano .env

I manually added the key laravel generated to my .env file

APP_KEY=xlhF31NeOlibJcoOW9tvZg7TkHcAZI3a
0

For Laravel 5.1, if the .env file does not exist, duplicate the .env.example file, rename it to .env, then run php artisan key:generate (as opposed to hardcoding a default in the config/app.php file).

The artisan command should update the APP_KEY in the .env file with a 32 character string to match the length expected by the 'cipher' => 'AES-256-CBC' (in the config/app.php file).

Last updated 8 years ago.
0

From the great new documentation for Laravel 5.1:

http://laravel.com/docs/5.1/installation#environment-configura...

"If you install Laravel via Composer, this file will automatically be renamed to .env. Otherwise, you should rename the file manually."

Last updated 8 years ago.
0

If you use the laravel installer, you have to create the .env file manually.

FYI, this is different to the previous versions of the Laravel installer. I assume that this will be fixed later on, but for now I simply do the following:

cp .env.example .env

and then simple re-run:

php artisan key:generate

Maybe this helps.

Last updated 8 years ago.
0

Don't forget to restart local web server if you're using "artisan serve"...

0

generate application key

code : " php artisan key:generate; "

this should slove the problem

0

Change this code in config/app.php 'key' => env('APP_KEY', 'SomeRandomString'), To 'key' => env('APP_KEY', 'YouChoiceStirng'), Then run command this command php artisan key:generate

Hurray You have Solved Problem!

0

Hi Kovah,

You save my problem..thank you.

(Had the same problem, "php artisan key:generate" worked well.

Maybe the docs and source should be updated, for example with "SomeRandomStringWith32Characters")

Cheers,

0

At first the key:generate command wouldn't work for me.

After messing around with it a bit, I found that all that was needed after running key:generate was running the command to clear my config cache:

php artisan config:clear

After that it worked perfectly! Also, I re-cached my config by running this next command but in reality I realized it actually clears the config for you so all that is needed is:

php artisan config:cache

Worked like a charm!

0

php artisan key:generate actually work for me

0

i had to add a 32 random string, php artisan key:generate didnt work for me, im using laravel version 5.1.16 (LTS)

0

I had to run php artisan key:generate and rename the file .env.example to .env.

The installation documentation on the Laravel site says by installing Laravel via composer this should be done but this isn't the case just now.

0

I just signed up just to thank you all for the solution regarding:

  • env.example to .env
  • php artisan key:generate
0

These solution works for me,Thanks for this great support

0

Kovah said:

Maybe the docs and source should be updated, for example with "SomeRandomStringWith32Characters" which would - magically - be exactly 32 characters long and solve this problem...

I really think that the default string should not work out of the box, otherwise nobody who's new to Laravel would ever change it, and their apps would be open to security problems.

0

php artisan key:generate works for me. thank you! :)

Last updated 8 years ago.
0

I think you should follow these steps:-

  • First: you must have .env file in your root directory

  • Second: in your config/app.php file, you must have 'cipher' => 'AES-256-CBC',

  • Third: php artisan key:generate

** note: never forget to restart the server again :"D

one or more steps should make you go on :-)

Last updated 7 years ago.
0

These steps didn't work for me, they may have helped but what I did was I removed the env() from the 'key' option in the app.php config file.

0

WTF?! SoSDylan, thank you! That solved it for me! After removing env() it worked. Than readding it and its still working ?! o.O

I think my first problem was to run make:auth after I already did some changes in my app.

Anyone knows why removing env() was my solution?

0

SoSDylan, and WDJac.

I experienced this problem and I wanted to let you know the reason that this worked.

It seems that the code that is generated is the following:

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

The problem is that the env() function, requires the name of the key in the env file to locate. Removing the env() will fix this, but it removes your ability to use the env files. Instead do this:

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

This will allow you to use the APP_KEY value in your env file correctly.

0

I did everything that was suggested here but when I launch http://localhost:800 I still receive the very same error message. Thank you

0

On version 5.2.30, doing 'php artisan key:generate' generated some key that was 44 characters long and didn't work with Cachet. After deleting a few characters to make it a 32 character string, it worked. Not sure if 32 characters is the limit? Some forums kept suggesting that it has to be 'at least' 32 characters, making it seem like having more wouldn't be a problem but was for me.

0

@ozanhazer way works for me.

Need to restart server when using

php artisan serve

command.

0

orphanedrecord said:

For Laravel 5.1, if the .env file does not exist, duplicate the .env.example file, rename it to .env, then run php artisan key:generate (as opposed to hardcoding a default in the config/app.php file).

The artisan command should update the APP_KEY in the .env file with a 32 character string to match the length expected by the 'cipher' => 'AES-256-CBC' (in the config/app.php file).

0

Hi , thank you for your support. Had the same problem, "php artisan key:generate" worked well and the suggest of orphanedrecord it was useful!

0

Just another problem that causes this result: I copied the entire project, but failed to copy .env. With no .env you get the Cipher/Key error.

0

I use JQuery for front end and in my case the problem persist until I changed 'Cipher' in config/ app.php to 'cipher' => MCRYPT_RIJNDAEL_128,

0

I could not solve this problem. I get this error when I try running key:generate. So what now?
Btw, I already have mcrypt installed.

Last updated 7 years ago.
0

levinhne said:

php artisan key:generate :)

Agree.. Simple solution. Try it. And it works

0

if the value of cipher in config/app.php is MCRYPT_RIJNDAEL_128 install mcrypt for your relevent php version

for php7

sudo apt-get install php7.0-mcrypt

Last updated 7 years ago.
0

I have same problem with Laravel 5.3 (on windows server). I did all possible attempts:checked .env file, config, artisan new key generation, cache:clear, config:clear, composer update, but the problem randomly persists.

Note that exactly the same code with exactly same version of apache, mysql, php, doesn't generate this problem on Mac OS.

I found that the key (first parameter of Encrypter constractor) arrives "sometimes" empty and of course it fails. Most of the time the key is correct, but randomly the key arrives empty from EncryptionServiceProvider that in turns asks it to the app config.

So the only solution that worked for me was to add an if ($key) in EncryptionServiceProvider so that the Encryption constructor doesn't get called with empty key.

Of course is not a "clean" solution nor it explains the problem, but at least avoids to find the log file filled with the error: RuntimeException: The only supported ciphers are AES-128-CBC and AES-256-CBC and pages are displayed correctly.

If this is a Laravel bug I don't know, but of course if someone could explain this I will be more then happy to know.

Below my modified class: just added the if($key) line before new Encrypter

class EncryptionServiceProvider extends ServiceProvider
{
    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('encrypter', function ($app) {
            $config = $app->make('config')->get('app');

            // If the key starts with "base64:", we will need to decode the key before handing
            // it off to the encrypter. Keys may be base-64 encoded for presentation and we
            // want to make sure to convert them back to the raw bytes before encrypting.
            if (Str::startsWith($key = $config['key'], 'base64:')) {
                $key = base64_decode(substr($key, 7));
            }
        if ($key)
            return new Encrypter($key, $config['cipher']);
        });
    }
}
Last updated 7 years ago.
0

develalfy said:

I think you should follow these steps:-

  • First: you must have .env file in your root directory

  • Second: in your config/app.php file, you must have 'cipher' => 'AES-256-CBC',

  • Third: php artisan key:generate

** note: never forget to restart the server again :"D

one or more steps should make you go on :-)

0

All these steps done many times. The error is random. This means that the server responds with no errors 100 time and next hit you get this error. Then keeps working aging for sometime

0

Some servers are using supervisor as the Queue Worker, you might need to restart it as well. I had restart my webserver still prompting the error.

[2017-08-13 00:00:01] live.ERROR: RuntimeException: No supported encrypter found. The cipher and / or key length are invalid. in /home/shiroamada/myproject/bootstrap/cache/compiled.php:7082
Stack trace:
#0 /home/shiroamada/myproject/bootstrap/cache/compiled.php(1289): Illuminate\Encryption\EncryptionServiceProvider->Illuminate\Encryption\{closure}(Object(Illuminate\Foundation\Application), Array)
#1 /home/shiroamada/myproject/bootstrap/cache/compiled.php(1242): Illuminate\Container\Container->build(Object(Closure), Array)
#2 /home/shiroamada/myproject/bootstrap/cache/compiled.php(1783): Illuminate\Container\Container->make('encrypter', Array)
#3 /home/shiroamada/myproject/bootstrap/cache/compiled.php(1478): Illuminate\Foundation\Application->make('encrypter')
#4 /home/shiroamada/myproject/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php(117): Illuminate\Container\Container->offsetGet('encrypter')
#5 /home/shiroamada/myproject/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(150): Illuminate\Queue\QueueManager->connection('redis')
#6 /home/shiroamada/myproject/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(108): Illuminate\Queue\Worker->pop('', 'default', '0', '3', '0')
#7 /home/shiroamada/myproject/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(70): Illuminate\Queue\Console\WorkCommand->runWorker('', 'default', '0', '128', false)
#8 [internal function]: Illuminate\Queue\Console\WorkCommand->fire()
#9 /home/shiroamada/myproject/bootstrap/cache/compiled.php(1187): call_user_func_array(Array, Array)
#10 /home/shiroamada/myproject/vendor/laravel/framework/src/Illuminate/Console/Command.php(150): Illuminate\Container\Container->call(Array)
#11 /home/shiroamada/myproject/vendor/symfony/console/Command/Command.php(263): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /home/shiroamada/myproject/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /home/shiroamada/myproject/vendor/symfony/console/Application.php(858): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /home/shiroamada/myproject/vendor/symfony/console/Application.php(205): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
```>execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#12 /home/venturegrab/webapps/app-venturegrab-stage/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#13 /home/venturegrab/webapps/app-venturegrab-stage/vendor/symfony/console/Application.php(858): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#14 /home/venturegrab/webapps/app-venturegrab-stage/vendor/symfony/console/Application.php(205): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Queue\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.