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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Removing padding when decrypting

843810Apr 15 2002 — edited Apr 19 2002
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 17 2002
Added on Apr 15 2002
4 comments
1,465 views