Reputation: 1
i need to protect a list of files ( file can be any type ) by password . i chose to use zip4j to do it . i use :
public static ZipFile creatZipFile(List<File> filesToAdd) {
try {
//This is name and path of zip file to be created
ZipFile zipFile = new ZipFile("test.zip");
//Initiate Zip Parameters which define various properties
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to deflate compression
//DEFLATE_LEVEL_FASTEST - Lowest compression level but higher speed of compression
//DEFLATE_LEVEL_FAST - Low compression level but higher speed of compression
//DEFLATE_LEVEL_NORMAL - Optimal balance between compression level/speed
//DEFLATE_LEVEL_MAXIMUM - High compression level with a compromise of speed
//DEFLATE_LEVEL_ULTRA - Highest compression level but low speed
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
//Set the encryption flag to true
parameters.setEncryptFiles(true);
//Set the encryption method to AES Zip Encryption
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
//AES_STRENGTH_128 - For both encryption and decryption
//AES_STRENGTH_192 - For decryption only
//AES_STRENGTH_256 - For both encryption and decryption
//Key strength 192 cannot be used for encryption. But if a zip file already has a
//file encrypted with key strength of 192, then Zip4j can decrypt this file
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
//Set password
parameters.setPassword("sendmail");
//Now add files to the zip file
zipFile.addFiles((ArrayList) filesToAdd, parameters);
return zipFile;
} catch (ZipException e) {
e.printStackTrace();
return null;
}
}
know i want to convert my zipFile to array of byte to send it as attachment in email .I find some method can do that but not by zip4j . anyone can help me ?
Upvotes: 0
Views: 612