【问题标题】:Migrate encryption key from Laravel 5.2 to 5.3将加密密钥从 Laravel 5.2 迁移到 5.3
【发布时间】:2017-09-27 18:22:05
【问题描述】:

我目前正在尝试从 Laravel 5.2 更新到 5.3。但是现在我在将加密从 MCrypt 转换为 OpenSSL 时遇到了问题,如升级指南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

【问题讨论】:

    标签: php laravel encryption


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-17
      • 1970-01-01
      • 2013-05-28
      • 2016-02-17
      • 1970-01-01
      • 2017-02-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多