2016-09-18 71 views
4

我目前正在嘗試從Laravel 5.2更新到5.3。但是現在我遇到了將加密從MCrypt轉換爲OpenSSL的問題,如升級指南https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0中所述。爲此,我按照上面的文檔中的建議寫了一條命令。但有一個錯誤:從Laravel 5.2遷移加密密鑰到5.3

[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 

回答

0

你手動覆蓋用戶的密碼加密? 默認情況下,如果您不更改任何內容,則不需要執行密碼遷移。 密碼未使用encrypt()進行加密,而是使用password_hash(), ,這就是有效負載無效的原因。