StormBeast's avatar

Encryption Configuration

So I'm trying to get encryption working in Lumen, just as it would in Laravel. I have set the API_KEY in .env and it is loaded in bootstrap/app, however I am still getting the following exception on decrypt:

No supported encrypter found. The cipher and / or key length are invalid.

I've also tried setting the key and cipher value in bootstrap/app, but I'm not sure if I have the syntax correct.

$app->key = env('APP_KEY', 'yNNH04mZplp7xDWTnw3r8AVvAiiAPtA7');
$app->cipher = 'AES-256-CBC';

Any help would be greatly appreciated, thanks!

0 likes
5 replies
bashy's avatar

Does it work on Laravel on the same server/machine?

Have you checked the contents of the key so it's 16 chars? As well as printing the APP_KEY via env()?

Make sure you have mcrypt installed and working.

bugsysha's avatar

Are you sure you didn't define that in .env.example file? Can you do next command without error?

php artisan key:generate
StormBeast's avatar

@bashy Yep, I'm running a laravel 5.1 instance on the same machine, encryption is working fine on there. As the cipher is AES-256-CBC, I believe the string should be 32 characters, as it is currently. And no, APP_KEY does not print, but I think this might have something to do with the differences between Lumen and Laravel. For instance, I load my .env in bootstrap/app, the configuration seems to differ.

@bugysha Unfortunately, the key namespace does not exist in Lumen.

bashy's avatar

Make sure Dotenv is enabled for Lumen.

Note: In order for your configuration values to be loaded, you will need to uncomment the Dotenv::load() method call in your bootstrap/app.php file.

Ref: http://lumen.laravel.com/docs/installation#configuration

Edit: not sure if that's what you meant by "loaded in bootstrap", sorry!

Please or to participate in this conversation.