【发布时间】:2020-11-24 02:47:47
【问题描述】:
这是我在 PHP 中的以下加密和解密,它工作正常,但我需要在 angular 7 中解密相同的东西,
Encryption in php using aes-256-cbc by following method
$this->data ="plaintext";
$this->
openssl_encrypt("plaintext", "aes-256-cbc", "1234567890",0,"1234567890")
但我尝试使用 crypto-js 但它返回空值,
CryptoJS.AES.decrypt("ciphertext","1234567890".toString(CryptoJS.enc.Utf8);
提出任何想法。
我的目标是加密 php 中的字符串并解密 angular 中的值
【问题讨论】:
-
你的代码语法完全错误:2个左括号,只右一个。
-
我放了例子,没关系
-
在您的 PHP 代码中,您使用了错误的键和 IV 大小。
-
Topaco,但它在 php 中解密
-
您必须将密钥和 IV 作为
WordArray:CryptoJS.AES.decrypt(ciphertext, keyWA, {iv: ivWA});传递。WordArrays 可以使用编码器创建,例如:var ivWA = CryptoJS.enc.Utf8.parse("1234567890123456");如果您随后在 both 代码中使用 same 键和 IV,它将起作用。