[英]How to encrypt zip file using zip4j
我想創建受密碼保護的ZIP:
// 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和監視文件
Zip4j支持文件列表的加密......
主要特點 :
- 從Zip文件創建,添加,提取,更新,刪除文件
- 讀/寫密碼保護的Zip文件
- 支持AES 128/256加密
- 支持標准Zip加密
- 支持Zip64格式
- 支持存儲(無壓縮)和Deflate壓縮方法
- 從Split Zip文件創建或提取文件(例如:z01,z02,... zip)
- 支持Unicode文件名
- 進度監視器
看一下這個示例代碼AddFilesWithAESEncryption.java :
// 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);
由於專利問題,Zip4j不支持文件列表的加密。
請參閱: http : //www.lingala.net/zip4j/forum/index.php?topic = 104.0
更新:
如鏈接中所述。 zip規范不包括文件列表的加密。 要隱藏文件名,您可以創建一個zip文件,包括您的文件再次通過zip封裝它。 因此,如果您打開zip2.zip,您將只看到“zip1.zip”而不是原始文件名。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.