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.