I wanna zip files with password protected archive. I have such imp:
public class ZipArchiverAdapter implements ZipArchiverPort {
private static final Logger log = LoggerFactory.getLogger(ZipArchiverAdapter.class);
@Override
public void compressFilesWithPassword(List<String> fileToZipPaths, String password) throws IOException {
String sourcePath = System.getProperty("java.io.tmpdir") + "supportPackage";
String destPath = sourcePath + ".zip";
System.out.println("Destination " + destPath);
ZipFile zipFile = new ZipFile(destPath, password.toCharArray());
for(String f: fileToZipPaths) {
zipFile.addFile(new File(f), getParameters());
}
}
private ZipParameters getParameters() {
ZipParameters zipParameters = new ZipParameters();
zipParameters.setCompressionMethod(CompressionMethod.DEFLATE);
zipParameters.setCompressionLevel(CompressionLevel.ULTRA);
zipParameters.setEncryptionMethod(EncryptionMethod.AES);
zipParameters.setAesKeyStrength(AesKeyStrength.KEY_STRENGTH_256);
zipParameters.setEncryptFiles(true);
zipParameters.setIncludeRootFolder(true);
return zipParameters;
}
}
And this code works. Archive is zipped with password.
The only problem with it is that anyone without knowing a password can open resulting zip file and see what files are inside. When You clicks on file it will require password from You.
But I wanna have files inside zip hidden with password. This can be achieved using any zip program.
I just don't know how to do this with zip4j
. I've check docs:
http://www.lingala.net/zip4j.html
https://github.com/srikanth-lingala/zip4j
but not find an answer.
Please help