How to create a normal password-protected ZIP archive?

17,178

Solution 1

since Android has a JVM , you can try to use all lib that you see for java (some will run , some not , and some changes of some library will be ok too) .

This way i'll copy past this answer fo the question (Write a password protected Zip file in Java):

After much searching, I've found three approaches:

A freely available set of source code, suitable for a single file zip. However, there is no license. Usage is AesZipOutputStream.zipAndEcrypt(...). http://merkert.de/de/info/zipaes/src.zip ( https://forums.oracle.com/forums/thread.jspa?threadID=1526137 )

UPDATE: This code is now Apache licensed and released at http://code.google.com/p/winzipaes/ . It worked for me (one file in the zip), and fills a hole in Java's opens source libraries nicely.

A commercial product ($500 at the time of writing). I can't verify if this works, as their trial license approach is complex. Its also a ported .NET app: http://www.nsoftware.com/ipworks/zip/default.aspx

A commercial product ($290 at the time of writing). Suitable only for Wnidows as it uses a dll: http://www.example-code.com/java/zip.asp

You must also know that maybe it won't be easy to adapt them to Android , but maybe you are lucky and some of this will run for you immediately .

Good luck!

Solution 2

I've searched a lot and finally found a good library that can zip files with password easily:

Zip:

ZipArchive zipArchive = new ZipArchive();
zipArchive.zip(targetPath,destinationPath,password);

Unzip:

ZipArchive zipArchive = new ZipArchive();
zipArchive.unzip(targetPath,destinationPath,password);

Rar:

RarArchive rarArchive = new RarArchive();
rarArchive.extractArchive(file archive, file destination);

The documentation of this library is good enough, I just added a few examples from there. It's totally free and wrote specially for android. Mvn Link

Share:
17,178
Lily
Author by

Lily

Updated on July 20, 2022

Comments

  • Lily
    Lily almost 2 years

    My app zips several files, saves the zip file to the SD card, and it emails the zip file to an address.

    The zipping is done with this code: Zipping Files with Android (Programmatically).

    Now the question is, how do I put a password on the zip file so that authorized individuals who opens it on a computer (Windows, Mac, or Ubuntu) would be able to extract the files with a supplied password?

    I read this post: Android zip file authentication, but it sounds to me that reading of the zip is done with another phone... or am I wrong? If anybody knows please let me know! Thanks!

  • Bhimbim
    Bhimbim about 4 years
    Can you give example to do it in kotlin ?.
  • petyr
    petyr almost 3 years
    the link in your answer leads to a 404
  • Milad Faridnia
    Milad Faridnia almost 3 years
    @petyr Thanks for pointing it. I updated my answer. Apparently the owner deleted the lib. but you can still use it from mvn repos.
  • petyr
    petyr almost 3 years
    Thanks alot! @MiladFaridnia, i will use the new link.