如何加密Laravel中的用户表单信息
How to encrypt user form information in Laravel
如何将用户发送给Laravel中的Store方法控制器的信息加密并在那里使用这些信息?
我有这样的表格输入
#parameters: array:5 [▼
"_token" => "TSxHdqBCiuikJxaO9iKybq0fTvqXy8kDc9Wd85rt"
"from" => "2"
"from_number" => "10000016"
"message" => "asdasd"
"mobile" => "asdasd"
]
我想像这样发送时加密数据 wrsa7dagsda76sd67awedtsdfjwerfh78wegfsr67a 并在控制器中再次使用 inputes
试试这个加密或解密 (AES-256) ...
public function encryption($data, $method){
$ciphering = "AES-256-CBC";
$options = 0;
$encryption_key = env('AES_ENCRYPT_KEY', 'default');
$encryption_iv = env('AES_ENCRYPT_IV', 'default');
if($method=='encrypt')
return openssl_encrypt(json_encode($data), $ciphering, $encryption_key, $options, $encryption_iv);
else if($method=='decrypt')
return json_decode(openssl_decrypt($data, $ciphering, $encryption_key, $options, $encryption_iv));
}
注意:如果要编码字符串而不是对象,请删除函数 json_encode
和 json_decode
如何将用户发送给Laravel中的Store方法控制器的信息加密并在那里使用这些信息?
我有这样的表格输入
#parameters: array:5 [▼
"_token" => "TSxHdqBCiuikJxaO9iKybq0fTvqXy8kDc9Wd85rt"
"from" => "2"
"from_number" => "10000016"
"message" => "asdasd"
"mobile" => "asdasd"
]
我想像这样发送时加密数据 wrsa7dagsda76sd67awedtsdfjwerfh78wegfsr67a 并在控制器中再次使用 inputes
试试这个加密或解密 (AES-256) ...
public function encryption($data, $method){
$ciphering = "AES-256-CBC";
$options = 0;
$encryption_key = env('AES_ENCRYPT_KEY', 'default');
$encryption_iv = env('AES_ENCRYPT_IV', 'default');
if($method=='encrypt')
return openssl_encrypt(json_encode($data), $ciphering, $encryption_key, $options, $encryption_iv);
else if($method=='decrypt')
return json_decode(openssl_decrypt($data, $ciphering, $encryption_key, $options, $encryption_iv));
}
注意:如果要编码字符串而不是对象,请删除函数 json_encode
和 json_decode