Initialization vector length in AES

若如初见. 提交于 2019-12-05 06:14:00

问题


I used AES with AES/CBC/PKCS5Padding with the following encryption and decryption code sections in Android:

cipher.init(Cipher.ENCRYPT_MODE, keySpec, new IvParameterSpec(IV1));
cipher.init(Cipher.DECRYPT_MODE, keySpec, new IvParameterSpec(IV2));

where IV1 and IV2 are randomly generated 16-byte initialization vectors. I did this to check if the original and decrypted texts will be different using different IVs in encryption and decryption parties. This leads the bytes of the decrypted text to be same as that of the original text after the first 16 bytes. For example if the original text is:

Enter your message here...

The decrypted text is:

*****************ge here... 

where * denotes a wrongly decrypted byte as it should be as IV1 and IV2 are different.

My question is: What to do to encrypt and decrypt text with length greater than 16 bytes using AES with initialization vector?

来源:https://stackoverflow.com/questions/10557784/initialization-vector-length-in-aes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!