java - 如何使用 zip4j 在 zip 密码保护的存档中隐藏带有密码的文件名
问题描述
我想用密码保护档案压缩文件。我有这样的小鬼:
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
但没有找到答案。
请帮忙
解决方案
来自的答案: 如何使用 zip4j 加密 zip 文件
由于专利问题,Zip4j 不支持文件列表的加密。
见:http ://www.lingala.net/zip4j/forum/index.php?topic=104.0
更新:
如链接中所述。zip 规范不包括文件列表的加密。要隐藏文件名,您可以创建一个 zip 文件,其中包括您的文件,通过再次压缩它来封装它。因此,如果您打开 zip2.zip,您只会看到“zip1.zip”而不是原始文件名。
推荐阅读
- vba - 我可以让 Access 使用文件名的可变部分和文件名的固定部分自动命名文件导出吗
- javascript - 返回组件时如何重构&&()
- c# - 回滚迁移错误 不允许从数据类型 datetime 到 int 的隐式转换。使用 CONVERT 函数运行此查询
- c# - 为什么在我的 C# MVC 部署的应用程序中会触发此对象引用异常?
- mongodb - 从 mongo 集合中选择特定字段不起作用
- sql - AgensGraph 中的混合查询示例
- laravel - 如何将数据从一张表移动到另一张表?
- javascript - Firefox 中的 WebRTC 事件
- java - 如果文件存在,如何创建备份文件
- java - RestAssured with Mockito:模拟 dao 存储库