如何解决如何使用zip4j
我想使用受密码保护的存档压缩文件。我有这样的小鬼:
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;
}
}
此代码有效。存档已压缩密码。
唯一的问题是,任何不知道密码的人都可以打开生成的zip文件并查看其中包含哪些文件。当您单击文件时,它将要求您输入密码。
但是我想在zip中用密码隐藏文件。可以使用任何zip程序来实现。
我只是不知道如何使用zip4j
执行此操作。我检查了文档:
http://www.lingala.net/zip4j.html
https://github.com/srikanth-lingala/zip4j
但找不到答案。
请帮助
解决方法
答案来自: How to encrypt zip file using zip4j
Zip4j不支持文件列表的加密,原因是 专利问题。
请参阅:http://www.lingala.net/zip4j/forum/index.php?topic=104.0
更新:
如链接中所述。邮编规范不包括 文件列表的加密。要隐藏文件名,您可以创建一个 包含文件的zip文件通过再次压缩将其封装。因此,如果 您打开zip2.zip,您只会看到“ zip1.zip”,而不是原始 文件名。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。