I need to set password protection for Zip folder via java, not for zip folder files. Without password i should not be able to open the Zip folder.
This is the code i found from google.
public static void encrypt(String key, InputStream is, OutputStream os)
throws Throwable {encryptOrDecrypt(key, Cipher.ENCRYPT_MODE, is, os);
}
Done using winzipaes1.0.1.jar...
Sample Code...
import java.io.File;
import java.io.IOException;
import de.idyl.winzipaes.AesZipFileEncrypter;
import de.idyl.winzipaes.impl.AESEncrypterBC;
public class Practice1Main {
public static void main(String[]args) throws IOException{
File aNewZipFile = new File("src.zip");
File existingUnzippedFile = new File("src.txt");
AESEncrypterBC encrypter = new AESEncrypterBC();
encrypter.init("password", 0); // The 0 is keySize, it is ignored for AESEncrypterBC
AesZipFileEncrypter zipEncrypter = new AesZipFileEncrypter(aNewZipFile, encrypter);
zipEncrypter.add(existingUnzippedFile, "src.txt", "password");
zipEncrypter.close();
}
}
The only free library I know of that does this is winzipaes . It has an Apache licence.
Google Code project page => https://code.google.com/p/winzipaes/
Maven Repo Link => http://mvnrepository.com/artifact/de.idyl/winzipaes
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.