How to encrypt the information sent by the user to the Store method controller in Laravel and use the information there?
i have a form like this inputes
#parameters: array:5 [▼
"_token" => "TSxHdqBCiuikJxaO9iKybq0fTvqXy8kDc9Wd85rt"
"from" => "2"
"from_number" => "10000016"
"message" => "asdasd"
"mobile" => "asdasd"
]
i want encrypt data when send like this wrsa7dagsda76sd67awedtsdfjwerfh78wegfsr67a and in controller again use inputes
CodePudding user response:
Try this for encryption or decryption (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));
}
Note: If you want to encode string instead of object, remove function json_encode
and json_decode