使用CryptoJS库在密文对象中可见密钥和IV

时间:2019-08-02 13:14:59

标签: aes cryptojs

我正在尝试使用CryptoJS库对一些文本进行加密/解密。

到目前为止,我要做的是生成一个随机密钥和iv,然后调用AES.encrypt函数对文本进行加密。

例如

const key = this.generateRandomBytes(32);
const iv = this.generateRandomBytes(16);
let ciphertext = CryptoJS.AES.encrypt("secretMessage", key, { iv: iv });
console.log(ciphertext);

我注意到的是密文对象包含密钥和IV,因此如果执行ciphertext.iv,我可以得到iv值。 这意味着,通过发送密文对象,攻击者可以获取iv和密钥值并解密消息。

这是正常行为吗?

示例:

key: rGV5ig6haSCITFt3qijtz6upLRwqqTYc 
iv: JYtl1p6QjXEC31l2 
ciphertext: cc7b280b4183a52edf953d67e2780540 

Inside the ciphertext object: 

iv: $super: {init: ƒ, toString: ƒ, concat: ƒ, clamp: ƒ, clone: ƒ, …} init: ƒ () sigBytes: 16 words: (4) [2104546036, 2077723482, 1293309165, -1744950810] __proto__: Object
key: $super: {init: ƒ, toString: ƒ, concat: ƒ, clamp: ƒ, clone: ƒ, …} init: ƒ () sigBytes: 32 words: (12) [811130221, 2012216235, 445216844, 1154159480, 158586942, 1801599139, -1829338835, 1906315595, 2104546036, 2077723482, 1293309165, -1744950810] __proto__: Object

0 个答案:

没有答案