我尝试将加密的数据从laravel API发送到Angular9。
我可以像这样在Laravel中使用Crypt :: encrypt加密数据:
$to_email = $request->email;
$dataToEncrypt = "id_ent=" . $request->ent_id . "&id_agenda=" . $request->agenda_id;
$dataEncrypted = Crypt::encrypt($dataToEncrypt);
$data = array('link' =>
"http://localhost:4200/registerUser?d=" . $dataEncrypted);
Mail::send('mailRegistrationUser', $data, function ($message) use ($to_email) {
$message->to($to_email)
->subject('Créer votre compte !');
$message->from('contact@test.com', 'Création de votre compte');
});
我在前后共享APP_KEY,因此它们具有相同的密钥。
一切正常,我可以像这样在我的角度应用程序中恢复数据:
getEncryptedData() {
this.encryptedData = this.route.snapshot.queryParamMap.get('d');
if (this.encryptedData === null) {
this.router.navigate(['/inscription']);
}
this.decryptedData = this.cryptoService.get(this.encryptedData);
console.log(this.decryptedData);
}
不幸的是,以下方法:
this.cryptoService.get(this.encryptedData);
返回一个空字符串...
以下是服务中的方法:
keys = '123abc'; //this is a exemple. I use de key from laravel...
get(value) {
let key = CryptoJS.enc.Utf8.parse(this.keys);
let iv = CryptoJS.enc.Utf8.parse(this.keys);
let decrypted = CryptoJS.AES.decrypt(value, key,
{
keySize: 128 / 8,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
}
);
return decrypted.toString(CryptoJS.enc.Utf8);
}
如果有人有主意...