首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用zip4j加密压缩文件

如何使用zip4j加密压缩文件
EN

Stack Overflow用户
提问于 2013-02-26 17:16:34
回答 2查看 9.6K关注 0票数 8

我想创建受密码保护的ZIP:

代码语言:javascript
运行
复制
    // Set the compression level
    parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

    // Set the encryption flag to true
    // If this is set to false, then the rest of encryption properties are ignored
    parameters.setEncryptFiles(true);

    // Set the encryption method to Standard Zip Encryption
    parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);

    // Set password
    parameters.setPassword(password);

但是这只加密了zip中的文件,但我可以打开这个zip并查看其中的文件

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-11-07 20:28:09

由于专利问题,Zip4j不支持加密文件列表。

请参阅:http://www.lingala.net/zip4j/forum/index.php?topic=104.0

更新:

如链接中所述。zip规范不包括文件列表的加密。要隐藏文件名,您可以创建一个zip文件,包括您的文件,通过再次压缩它来封装它。因此,如果您打开zip2.zip,您将只看到"zip1.zip“,而不是原始文件名。

票数 1
EN

Stack Overflow用户

发布于 2017-01-10 19:43:23

Zip4j支持文件列表的加密...

Key features

统一码文件创建、添加、解压、更新、删除受file

  • Read/Write密码保护的Zip files

  • Supports AES128/256 Encryption

  • Supports标准Zip Encryption

  • Supports统一码文件format

  • Supports存储(无压缩)和Deflate压缩method

  • Create或从拆分的Zip文件提取文件(例如:...zip)

  • Supports names

  • Progress
  • Zip64 z01 z02

看一下这个示例代码AddFilesWithAESEncryption.java

代码语言:javascript
运行
复制
// Initiate ZipFile object with the path/name of the zip file.
ZipFile zipFile = new ZipFile("c:\\ZipTest\\AddFilesWithAESZipEncryption.zip");

// Build the list of files to be added in the array list
// Objects of type File have to be added to the ArrayList
ArrayList filesToAdd = new ArrayList();
filesToAdd.add(new File("c:\\ZipTest\\sample.txt"));
filesToAdd.add(new File("c:\\ZipTest\\myvideo.avi"));
filesToAdd.add(new File("c:\\ZipTest\\mysong.mp3"));

// Initiate Zip Parameters
ZipParameters parameters = new ZipParameters();
// set compression method to deflate compression
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); 
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_ULTRA); 

// Set the encryption flag to true
parameters.setEncryptFiles(true);

// Set the encryption method to AES Zip Encryption
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);

// Set AES Key strength. Key strengths available for AES encryption are:
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);

// Set password
parameters.setPassword("test123!");

// Now add files to the zip file
zipFile.addFiles(filesToAdd, parameters);
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15085249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档