1

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

masterdany88
  • 5,041
  • 11
  • 58
  • 132

1 Answers1

2

Answer from: How to encrypt zip file using zip4j

Zip4j does not support the encryption of the file list because of patent issues.

See: http://www.lingala.net/zip4j/forum/index.php?topic=104.0

Update:

As stated in the link. The zip-specification does not include the encryption of the filelist. To hide the filenames you can create a zip-file including your files encapsulate it by zip it again. Hence if you open zip2.zip you will only see "zip1.zip" and not the original filenames.

masterdany88
  • 5,041
  • 11
  • 58
  • 132