Search code examples
javaandroidpasswordsunzip

How to unzip a password-protected archive created by Linux, using Java


I am working on an Android project recently and met an issue. I send a request to webservice and got a zip file with password protection. The zip file is create using the Linux command

zip -P 123123123123123123 test.zip test.txt

I want to unzip it with Java. Because there is no standard API support so I need a third library.

  1. I have tried winzipaes, but it prompts that my zip file is not in the AES-256 format.
  2. I cannot use sevenzipjbinding, it's too large.

Do you have any suggestion about this? Do you know what algorithm Linux used to encrypt the zip file?


Solution

  • Finally, I done with zip4j.

    1. Download zip4j-1.3.1 and import it to project.

    2. Sample Code:

      ZipFile zipFile = new ZipFile(YourZipFile);
      if(zipFile.isEncrypted()){
         zipFile.setPassword(Password);
      }
      zipFile.extractAll(Destination);