chevron_left
600 points
7 3 3

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

Photo by jwvein

Table of Content:

                1 - No supported encrypter found. The cipher and / or key length are invalid. 
                2 - What are the reasons behind this error message? 
                3 - The Solution 
                4 - The Conclusion

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.

If you read this far, tweet to the author to show them you care. Tweet a Thanks

More Posts

Invalid csrf token 'null' was found on the request parameter '_csrf' or header 'x-csrf-token'. NoirHusky - Sep 20
Java_home is not set and no 'java' command could be found in your path. Bushra Rubab - Sep 26
There is a problem with the resource you are looking for, and it cannot be displayed. zhteja - Aug 13
Failed To Decode Response zlib_decode() Data Error zhteja - Sep 22
Your requirements could not be resolved to an installable set of packages zhteja - Aug 1
Lambda expressions are not supported in source 1.7 zhteja - Jul 24
GPG can’t check signature no public key zhteja - Jul 16
Error 1452: cannot add or update a child row: a foreign key constraint fails Ankur Ranpariya 1 - Aug 28
No Valid Open PGP Data Found zhteja - Sep 15
The given key was not present in the dictionary. zhteja - Aug 9
Error: Enoent: No Such File Or Directory Open zhteja - Sep 19
Env: python: no such file or directory zhteja - Aug 7
Install and/or enable a PHP accelerator (highly recommended) JimCoder - May 28
Failed to load resource: the server responded with a status of 404 (not found) Ankur Ranpariya - Sep 18
Sdk location not found. define location with sdk.dir in the local.properties Hussain Zafar - Jun 10
Write a Program to Print First x Terms of the Series 3n+2 which are not Multiples of 4 beekip - Sep 20
Given a string, return a string where for every char in the original, there are two chars. Ankur Ranpariya - Jul 19
The bucket you are attempting to access must be addressed using the specified endpoint Hussain Zafar - Jun 7
There are 4 bytes in an ipv4 address. what is the highest decimal value you can have for one byte? James - Jun 1
The python path in your debug configuration is invalid. Bushra Rubab - Sep 23