Reputation: 23
I am able to create a zip file and add files using the zip4j library but the problem is the password is set only for the files inside the zip, so I am able to open the zip and see the file list, which I don't want. I want to set a password for the zip archive.
Any suggestions?
Upvotes: 2
Views: 359
Reputation: 53462
It's not the fault of the library - Zip format does not support this:
The Zip file format is such that the files added to a Zip file are encrypted, whereas the Zip file itself is not. Therefore, any user can open a Zip file and see the list of files even when those files are encrypted. However, the user will not be able to extract or view the encrypted files unless he or she enters the correct password to decrypt them.
To hide the names of the files in your encrypted Zip file, you can double zip them.
So you can make a .zip from your .zip for this. It doesn't seem to be possible in any other way.
Edit: @oleg.cherednik pointed out that current versions of the zip specification do support this, but the support doesn't seem to be implemented in libraries. So in practice you would need to double-zip your files.
Upvotes: 2
Reputation: 18245
This is APPNOTE.TXT - .ZIP File Format Specification. You can find there 7.3 Single Password - Central Directory Encryption. The problem is this feature is protected and looks like it is not in public access. You cannot find any open-source tool that supports this. (believe me, I have tried it).
Only one application that supports this is PKWARE's SecureZIP for Windows. You can find a free version of this tool as well.
All you can do in the java application is zip files twice.
Upvotes: 0