迁移Laravel 5.2到5.3的加密密钥

4

我目前正在尝试将Laravel 5.2升级到5.3。但是,现在我遇到了一个问题,即转换加密方式从MCrypt到OpenSSL,正如upgrade guide https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0中所述。为此,我按照上述文档建议编写了一个命令。但是出现了一个错误:

[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

指令:

<?php
namespace App\Console\Commands;

use App\User;
use Illuminate\Console\Command;
use Laravel\LegacyEncrypter\McryptEncrypter;

class McryptToOpenSSL extends Command
{
/**
 * The name and signature of the console command.
 *
 * @var string
 */
protected $signature = 'key:migrate';

/**
 * The console command description.
 *
 * @var string
 */
protected $description = 'Migrates key from deprecated Mcrypt to OpenSSL.';

/**
 * Create a new command instance.
 *
 * @return void
 */
public function __construct()
{
    parent::__construct();
}

/**
 * Execute the console command.
 *
 * @return mixed
 */
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(由于安全原因,密钥略有更改)

APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:3VU8u79ZU0dObazwvd2lHHOAVRJjy5kvzXKeKtcHVYk=
APP_KEY_LEGACY=zejqrdy7WjA58xGoSuj634RYXB97vLyp
1个回答

1
你是否手动覆盖了用户密码的加密方式? 默认情况下,如果您没有更改任何内容,则不需要进行密码迁移。 密码不是使用encrypt()进行加密,而是使用password_hash(), 这就是负载无效的原因。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接