41

I'm using Laravel 5.0 for all my projects. Yesterday, I've updated my PHP version from 7.0.x to version 7.1.0. Once updated, I tried opening my Laravel project and saw this message below:

ErrorException in Encrypter.php line 303: 
Function mcrypt_get_iv_size() is deprecated

in Encrypter.php line 303
at HandleExceptions->handleError('8192', 'Function mcrypt_get_iv_size() is deprecated', 'C:\wamp64\www\project1\vendor\laravel\framework\src\Illuminate\Encryption\Encrypter.php', '303', array()) in Encrypter.php line 303

May I know how can I solve this ? Does using Laravel 5.3 solve the problem? I don't feel like updating my Laravel to 5.3 because it's a huge project and it will takes a long time to update. There are too much differences between these two versions. Lots of codes need to be modified.

Is there an easier way to solve this issue?

2
  • Can't you use openssl_cipher_iv_length?
    – Irvin
    Commented Dec 8, 2016 at 3:27
  • It is best not to use mcrypt, it is abandonware, has not been updated in years and does not support standard PKCS#7 (née PKCS#5) padding, only non-standard null padding that can't even be used with binary data. mcrypt has many outstanding bugs dating back to 2003. The mcrypt-extension is deprecated will be removed in PHP 7.2. Instead consider using defuse or RNCryptor, they provide a complete solution and are being maintained and is correct.
    – zaph
    Commented Jul 10, 2017 at 14:13

4 Answers 4

32

This error occurs because you probably have something other than AES-256-CBC as your cipher in your config/app.php file that depends on the mcrypt extension. Perhaps you are using MCRYPT_RIJNDAEL_256 or MCRYPT_RIJNDAEL_128?

The best thing you can do without a full-blown Laravel upgrade is install the legacy encrypter and use it to update all your encrypted data to use the AES-256-CBC cipher which has been the default cipher since Laravel 5.1, I believe. Once you do this, you should be able to use PHP 7.1 for your Laravel application.

2
  • 2
    Changing cipher in config/app.php does not help: 'cipher' => 'AES-256-CBC',
    – Debiprasad
    Commented Aug 4, 2017 at 12:44
  • Changing the cipher is only part of the process. Using that cipher should definitely stop the mcrypt error unless something else in your application is using mcrypt. Commented Aug 4, 2017 at 19:41
31

Add this to the beginning of the config/app.php:

error_reporting(E_ALL ^ E_DEPRECATED);

Source: https://stackoverflow.com/a/42515505/225790

2
  • 3
    That's great, but just for local development. In production you need to have everything set properly.
    – istavros
    Commented May 7, 2019 at 20:45
  • @istavros If the environment is better updated than your code, then you should update your code to the better version if you don't want to get errors for deprecated functions. But sometimes it might be possible to update your code for some reason but the environment needs to be updated. Then such workarounds can help you. You can work with deprecated features before it gets obsolete.
    – Debiprasad
    Commented Oct 21, 2019 at 6:48
22

In your config/app.php configuration file, you should update the cipher to "AES-256-CBC" and set your key to a random 32 byte string which may be securely generated using php artisan key:generate

2
  • Worked for me. I had to regenerate the key using php artisan key:generate. I tried without regenerating the key and it didn't work. Afterword, it did.
    – zvineyard
    Commented Mar 26, 2017 at 16:01
  • worked for me, in config/app.php => 'cipher' => 'AES-256-CBC', and "php artisan key:generate" Commented Mar 22, 2019 at 19:19
1

to solve this just change cipher in app.php from 'MCRYPT_RIJNDAEL_128' to 'AES-256-CBC'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.