Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to create password protected 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);

but this just encrypt files inside of zip but I can open this zip and watch file inside it

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
613 views
Welcome To Ask or Share your Answers For Others

1 Answer

Zip4j supports the encryption of the file list...

Key features:

  • Create, Add, Extract, Update, Remove files from a Zip file
  • Read/Write password protected Zip files
  • Supports AES 128/256 Encryption
  • Supports Standard Zip Encryption
  • Supports Zip64 format
  • Supports Store (No Compression) and Deflate compression method
  • Create or extract files from Split Zip files (Ex: z01, z02,...zip)
  • Supports Unicode file names
  • Progress Monitor

Take a look at this example code 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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...