Removing padding when decrypting
843810Apr 15 2002 — edited Apr 19 2002Hi there
I have a question concerning decryption.
Suppose my plaintext block size is 8 bytes, and my ciphertext block size is 16 bytes. If I encrypt 12 bytes, it makes 2 full blocks (16 bytes) after padding, and is encrypted into 32 bytes. The cipher takes care of adding the padding.
During decryption, if I read bytes in from a stream, I would expect to be able to read in all 32 encrypted bytes at once, and pass these to update() in the cipher. This will return 16 bytes of unencrypted data (the cipher does not remove the padding).
So I get to the end of the file, having passed 32 bytes in to update(), and so I call doFinal(). But I've already received the unencrypted data from the cipher, so it doesn't have the opportunity to remove padding from the last block!
What is the solution to this problem, other than having my program remove the padding itself? Is there a recognised way to get the cipher to do this automatically?
Thanks
Rich