英文:
How to hide file names with password inside zip password protected archive using zip4j
问题
Sure, here is the translated code segment:
我想要用带密码保护的压缩档案来压缩文件。我有以下实现:
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;
}
}
Please let me know if you need further assistance.
英文:
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
答案1
得分: 2
来自:
https://stackoverflow.com/questions/15085249/how-to-encrypt-zip-file-using-zip4j
由于专利问题,Zip4j不支持对文件列表进行加密。
参见:http://www.lingala.net/zip4j/forum/index.php?topic=104.0
更新:
如链接中所述,zip规范不包括对文件列表的加密。为了隐藏文件名,您可以创建一个包含您的文件的zip文件,然后再次对其进行压缩。因此,如果您打开zip2.zip,您只会看到"zip1.zip",而不会看到原始文件名。
英文:
Answer from:
https://stackoverflow.com/questions/15085249/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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论