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!

Encryption/decryption problem with ZIP files

843811Feb 9 2009 — edited Feb 10 2009
Hi all,

The goal of my program is to add/extract files in/from a ZIP archive, while file data is encrypted.

I wrote an example source code that :
- creates an empty archive (also called box in the code)
- adds 2 existing files to it
- extracts the 2 files from it, and write them to another disk location

What works : encryption and decryption of ZIP entry names, while files data is not encrypted. Files are correctly added and extracted.

What doesn't work : when I add files data encryption, only the first file is extracted, and there is no error in console.

The problem takes place in add() and extract() methods, when I replace :
// this is data copying without encryption
while ((len = addedFileIn.read(buf)) > 0) {
  out.write(buf, 0, len);
}
by :
// this is data encryption, dealing with CipherOutputStream embedding ZipOutputStream
this.encrypt(addedFileIn, out);
Do you see what's wrong ? Is there another efficient way to encrypt data (I also tried to encrypt bytes directly) ?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 10 2009
Added on Feb 9 2009
7 comments
1,177 views