I am currently trying to upgrade from Laravel 5.2 to 5.3. But now I have a problem converting encryption from MCrypt to OpenSSL, as described in the update guide https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0 here. To do this, I wrote the command suggested in the documents above. But there is an error:
[2016-09-18 11:07:46] local.ERROR: exception 'Illuminate\Contracts\Encryption\DecryptException' with message 'The payload is invalid.' in /home/vagrant/Code/bob/vendor/laravel/legacy-encrypter/src/BaseEncrypter.php:44
Team:
<?php
namespace App\Console\Commands;
use App\User;
use Illuminate\Console\Command;
use Laravel\LegacyEncrypter\McryptEncrypter;
class McryptToOpenSSL extends Command
{
protected $signature = 'key:migrate';
protected $description = 'Migrates key from deprecated Mcrypt to OpenSSL.';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$legacy = new McryptEncrypter(env('APP_KEY_LEGACY'));
$users = User::all();
foreach ($users as $user) {
$user->password = encrypt(
$legacy->decrypt($user->password)
);
$user->save();
}
}
}
.env (keys are slightly changed for security reasons)
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:3VU8u79ZU0dObazwvd2lHHOAVRJjy5kvzXKeKtcHVYk=
APP_KEY_LEGACY=zejqrdy7WjA58xGoSuj634RYXB97vLyp
source
share