|
楼主 |
发表于 2019-12-11 15:09:24
|
显示全部楼层
广东省佛山市
- aesManaged.Key = rfc2898DeriveBytes.GetBytes(aesManaged.KeySize / 8);
- aesManaged.IV = rfc2898DeriveBytes.GetBytes(aesManaged.BlockSize / 8);
复制代码
如上图,PBKDF2计算出Key的Hash值转base64即密钥kJQkmJBeaAHHxMzwd18WT129AG3mtWlL59Em9qAVgew=
请问,IV :aesManaged.IV = rfc2898DeriveBytes.GetBytes(aesManaged.BlockSize / 8) 如何通过PBKDF2算出来呢?
百毒了很多资料对C#的rfc2898DeriveBytes、GetBytes概念还是很模糊,主要想通过CryptoJS直接计算IV
附aesManaged.Key的CryptoJS计算函数(感谢qingshanlushui):
- var key = CryptoJS.enc.Base64.parse("kJQkmJBeaAHHxMzwd18WT129AG3mtWlL59Em9qAVgew=");
- var iv = CryptoJS.enc.Base64.parse("qkXFhdnuBrhiMRHG7Eo/SQ==");
- function AES_Encrypt(word) {
- var srcs = CryptoJS.enc.Utf8.parse(word);
- var encrypted = CryptoJS.AES.encrypt(srcs, key, {
- iv: iv,
- mode: CryptoJS.mode.CBC,
- padding: CryptoJS.pad.Pkcs7
- });
- return encrypted.toString();
- }
- function AES_Decrypt(word) {
- var srcs = word;
- var decrypt = CryptoJS.AES.decrypt(srcs, key, {
- iv: iv,
- mode: CryptoJS.mode.CBC,
- padding: CryptoJS.pad.Pkcs7
- });
- return decrypt.toString(CryptoJS.enc.Utf8);
- }
复制代码
|
|