2017-03-08 78 views
1

如何對類對象進行加密和解密,將其存儲到數據庫中。其實我想保護我的數據庫,如果有人偷了它,然後無法讀取它。如何對laravel進行加密和解密5.4.6類對象

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

嗨艾米爾你正在使用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 
+0

作品

那很好,謝謝@AdnanMumtaz – Savvy

相關問題