AES Initialization Vector Length

I used AES with AES / CBC / PKCS5Padding with the following sections of encryption and decryption code 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 random 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 sessions. This leads to the fact that the bytes of the decrypted text will be the same as the source text after the first 16 bytes. For example, if the source text is:

Enter your message here...

Decrypted text:

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

where * denotes an erroneously decrypted byte, since it must be the same as IV1 and IV2.

My question is: what should I do to encrypt and decrypt text longer than 16 bytes using AES with an initialization vector?

+2
source

Source: https://habr.com/ru/post/1689137/


All Articles