Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use zip4j to extract an zip file with password protection

I am trying to unzip a zipfile with password protection. I know there is a java library named "zip4j" that could help me. But I am failing to open the zip4j website to see the tutorial.

I had download zip4j library with another mirror but I don't know how to use it. Is there anyone that could paste example code for using zip4j unzip password protection zip file?

zip4j website

thanks so much!

like image 848
wayne_bai Avatar asked Jun 24 '12 03:06

wayne_bai


People also ask

Can zip files have passwords?

If you put the files you'd like to protect in a zip file, you can then apply a password. In Windows Explorer, highlight and right-click on the files you would like to put into a zipped file. Select Send to, then Zip folder (compressed). Double-click the zipped file, then select File and Add Password.

Can encrypted zip files be hacked?

zip files can be easily broken with off-the-shelf hacking tools,” the Oregon Democrat writes in a letter obtained by CyberScoop. “This is because many of the software programs that create . zip files use weak encryption algorithms by default.”


1 Answers

Try the following and make sure you are using the most recent Zip4j library (1.3.1):

String source = "folder/source.zip";
String destination = "folder/source/";
String password = "password";

try {
    ZipFile zipFile = new ZipFile(source);
    if (zipFile.isEncrypted()) {
        zipFile.setPassword(password);
    }
    zipFile.extractAll(destination);
} catch (ZipException e) {
    e.printStackTrace();
}
like image 145
developer110 Avatar answered Oct 04 '22 14:10

developer110