Initialization vector length in AES
Asked Answered
F

0

2

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?

Forefront answered 11/5, 2012 at 19:55 Comment(1)
This problems seem to be unrelated to the size of the IV. The size of the IV should always be equal to the AES block size, which is 16 byte. The IV will be used as the initial input for the block cipher mode. You specified you are using CBC as the block cipher mode. From what you are describing, it seems to me that only the first block is encrypted. But it is impossible for me to give an answer to your problem, without seeing the code you are using to do the actual encryption, since you only posted the code for initializing the cipher, not the code that feeds data into the cipher.Flashgun

© 2022 - 2024 — McMap. All rights reserved.