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

·

3 min read

It is easy to get this error when you start a new project that uses the Laravel framework. The solution is to set a key in the .env file.

The key length is 256 bits or 32 bytes in size. The cipher length is also 256 bits or 32 bytes long. Both these lengths are considered secure by modern standards and should not be changed unless required to do so by your organization’s security policy or by an audit requirement set forth by government agencies like the NSA.

There are several modes available like ECB mode (Electronic Code Book), CBC (Cipher Block Chaining), GCM (Galois Counter Mode), PCBC (Pseudo-Counter Mode), and OFB (Output Feedback). If you are unsure which mode would be best for your use case, consult with a cryptographer for advice before making a decision about which one to choose as there may be specific requirements surrounding certain modes given their weaknesses when compared against other options available within a particular cryptographic algorithm suite such as AES-256-CBC that could affect how much overhead they incur during operation due to additional setup time required prior execution time spent generating keysets rather than performing actual computations on data after they have been generated through initialization procedures performed prior execution time spent generating keysets rather than performing actual computations on data after they have been generated through initialization procedures performed prior execution time spent generating keysets rather than performing actual computations on data after they have been generated through initialization procedures performed priors

Image description

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

If you are working on the Laravel framework and you forgot to generate an encryption key, or if you used a third-party project that does not has .env file. This runtime exception will be shown no supported encrypter found. The cipher and / or key lienght are invalid. As I mentioned above in the introduction section the key length will be 256 bits or 32 bytes.

What are the reasons behind this error message?

The reason behind this message is that the .env file doesn’t exist or because you haven’t generated the APP_KEY in the .env file. The .env file may not exist because you clone a Laravel project or download it from a repository where this file was not present. It may occur because you forgot to generate the APP_KEY in .env file.

The Solution

The solution is simple. What is the reason behind this message just run the blew command, it will generate APP_KEY and set it in .env file

$ php artisan key:generate

Once executed the the command you will prompt the execution message like this

$ php artisan key:generate

Application key [base64:b6GcD7jRA44BKel6VShUe/hOdF3HAGi9+B1ZeLE/8pk=] set successfully.

What the command will do for you. If you will check .env file before executing the command its code will look like this (if the file exists and you forgot to generate the APP_KEY)

APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
APP_URL=http://localhost

After the execution of the command it will amend the file like this

APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:b6GcD7jRA44BKel6VShUe/hOdF3HAGi9+B1ZeLE/8pk=
APP_URL=http://localhost

If the .env file did not exist then the command will generate the .env file and produce the code and set it in .env file.

Now all set to go

Conclusion

Remember that no matter what you are using, you should always be careful when setting up security measures on your application and not forget to change the encryption key as well. I hope you find my code and post useful in putting it into action. How to deal with the issue – No supported encrypter found. The cipher and / or key length are invalid. in the Laravel 5 framework If you require assistance or input, please leave it in the comments or write us as feedback. If you have a good suggestion for this topic, please share it. Your feedback will assist us in better serving you and improving our services.