This is an article which is specifically discussed an error shown as the title of this article. The error is ‘The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.’ The error itself can be shown in the following image :
It is an error which is also can be found in the Laravel log file as shown below :
[2017-04-28 06:16:00] local.ERROR: RuntimeException: The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths. in /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Encryption/Encrypter.php:43 Stack trace: #0 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php(27): Illuminate\Encryption\Encrypter->__construct('Tc2EiYme62mAZwe...', 'AES-256-CBC') #1 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Container/Container.php(746): Illuminate\Encryption\EncryptionServiceProvider->Illuminate\Encryption\{closure}(Object(Illuminate\Foundation\Application), Array) #2 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Container/Container.php(644): Illuminate\Container\Container->build(Object(Closure), Array) #3 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(709): Illuminate\Container\Container->make('encrypter', Array) #4 /var/www/html/testing/laravel-project/vendor/laravel/framework/src/Illuminate/Container/Container.php(864): Illuminate\Foundation\Application->make('encrypter')
The cause of the above error can be fall into the following reason :
1. The environment variables doesn’t have APP_KEY whenever the cipher defined in the app.php file located in config folder inside the root folder of web-based application using Laravel framework is set to ‘AES-128-CBC’ or ‘AES-256-CBC’. Below is the snippet code of config/app.php showing the definion of cipher field :
/* |----------------------------------------------------------------------- | 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',
As long as the cipher is set into ‘AES-128-CBC’ or ‘AES-256-CBC’, the following field named ” which is set in file .env located in the root folder of web-application using Laravel framework.
APP_KEY=base64:8bNcWn9rjqhmSQcY6wmU2h0dr6SZx6vHCoYo6KNByqQ=
The above is an example of APP_KEY which can be generated by executing the following command from the bash prompt :
php artisan key:generate
2. The APP_KEY in the file named .env is not defined. This is actually related with the reason stated in the first option. Defining the value of APP_KEY cannot be done randomly. As shown in the information previously, it can be generated by executing ‘php artisan key:generate’ from the command prompt specifically in the root folder of web-application using Laravel framework.
After solving and confirming the above things, the page should have been previewed normally.
One thought on “Laravel Error Message : The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.”