如何加密和解密类对象,将其存储到数据库中。实际上我想保护我的数据库,如果有人偷了它,那么就无法读取它。
Employee Controller
$employee = new Employee();
$employee->name = $request->get('name');
$employee->code = $request->get('code');
$employee->email = $request->get('email');
$employee->cell = $request->get('cell');
$employee->password = $request->get('password');
这里我想加密$ employee对象并将其存储到数据库中,并且还要解密它以再次查看它。请指导我
答案 0 :(得分:0)
你好Amir你正在使用laravel 5.4有辅助方法。
$employee = new Employee();
$employee->name = encrypt( $request->get('name'));
$employee->code = encrypt($request->get('code'));
$employee->email = encrypt($request->get('email'));
$employee->cell = encrypt($request->get('cell'));
$employee->password = encrypt($request->get('password'));
就是这样。您的整行已加密。确保数据库中的长度varchar大于100.否则,在需要时它将不会被解密。
如果你想简单地解密
decrypt($employee->name); // it will return string