Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

AES/CBC/NoPadding: CipherInputStream question.

843811Dec 17 2007 — edited Dec 18 2007
My esi.getInputStream(fis) actually creates a CipherInputStream with "AES/CBC/NoPadding". This seems to work just fine. BUT when I run this code:
FileInputStream fis = new FileInputStream("MyFile.txt");
FileOutputStream fos = new FileOutputStream("MyFile.cipher");
EncryptionServiceImpl esi = new EncryptionServiceImpl();
CipherInputStream cis = esi.getInputStream(fis);
byte[] bt = new byte[16];
int n;
while ((n = cis.read(bt)) != -1) {
	fos.write(bt, 0, n);
}
cis.close();
fos.close();
Only the first 16 bytes get written to the output file. I know that "AES/CBC/NoPadding" means it needs 16 bytes to process...BUT how do you do this when files are always different sizes?! I am basically trying to encrypt and decrypt streams with this algorithm. Ideas?

Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 15 2008
Added on Dec 17 2007
8 comments
4,453 views