为什么我无法解密数据库中的数据?

时间:2017-09-04 09:51:27

标签: php laravel

在此代码中,我使用AES256算法进行加密和解密,我可以加密数据,但无法从数据库中解密。为什么?这段代码有问题。它在控制台中显示我是假的。基本上我得到错误:

$decrypted=openssl_decrypt($parts[0], $this->AES_256_CBC, $this->encryption_key, 0,$this->iv);

在这。但是,当我在相同的功能中,它正常工作。这段代码中是否存在一些问题?如果是,请帮助我。

public function add_users(Request $request){
    $users = new User();
    $users->name=$request->name;
    $users->email = $request->email;
    $users->password=$request->password;
    $users->role=$request->role;
    $encrypted = openssl_encrypt($users->name, $this->AES_256_CBC, $this->encryption_key, 0,$this->iv);
    $encrypted1 = openssl_encrypt($users->email, $this->AES_256_CBC, $this->encryption_key,  0, $this->iv);
    $encrypted2 = openssl_encrypt($users->password, $this->AES_256_CBC, $this->encryption_key, 0,$this->iv);
    $encrypted3 = openssl_encrypt($users->role, $this->AES_256_CBC, $this->encryption_key, 0,$this->iv);
    DB::insert('insert into users (name,email,password,role) values(?,?,?,?)',[$encrypted,$encrypted1,$encrypted2,$encrypted3]);
}


public function edit(Request $request){

    $id = $request->id;
    $user = User::where(['id' => $id])->get()->toArray();
    $data = $user[0]['name'];
    $data = $data . ':' . $this->iv;
    $parts = explode(':', $data);
    $decrypted=openssl_decrypt($parts[0], $this->AES_256_CBC, $this->encryption_key, 0,$this->iv);
    dd($decrypted);
}

0 个答案:

没有答案
相关问题