Laravel

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

I got this issue while setting up LumenPassport in Laravel/Lumen micro framework.

Error

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

Use case:
When logging in user via LumenPassport /oauth/token endpoint

Route::get('/login', function (Request $request) {
    $http = new GuzzleHttp\Client;
    $response = $http->post('http://your-app.com/oauth/token', [
        'form_params' => [
            'grant_type' => 'password',
            'client_id' => 'client-id',
            'client_secret' => 'client-secret',
            'username' => 'username',
            'password' => 'password',
        ],
    ]);
});

Reason

As you can see in the error, lumen is complaining about “key length”, which key?

humm…

We are talking about APP_KEY, that must be stored in .env file.

Either you are missing that key in .env file or you have an incorrect length of the key.

Key must be base64 32 bytes.

Solution

  • Generate app key using Base64 String and place in .env APP_KEY= or
  • In Laravel run: php artisan key:generate
  • But if you are using Lumen, that doesn’t has key:generate command by default you can use this package (maxsky/lumen-app-key-generator) to add command to you Lumen app.

What is APP_KEY?

Want to know more about Laravel/Lumen APP_KEY, take a look at well written and explained article https://tighten.co/blog/app-key-and-you

Author: Danyal
I'm skilled programmer with expertise in Vue.js/Nux.js for front-end development and PHP Laravel for back-end development. I excel in building APIs and services, and also have experience in web server setup & maintenance. My versatile skill set allows you to develop and maintain web applications effectively, from the user interface to the server-side functionality. I love coding with never ending learning attitude, thanks for visiting danya.dk