Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a normal password-protected ZIP archive?

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!

like image 526
Lily Avatar asked Oct 14 '11 20:10

Lily


People also ask

How do I create a password protected zip file?

Right-click on the Zip file you wish to password protect. Choose WinZip. Click Encrypt. WinZip will ask for a password and then encrypt all files currently in the Zip file.

Can I password protect a zip file 7-Zip?

To password protect the archive file created by 7-Zip you must choose a password and enter it twice in the text boxes beneath “Encryption.” D.

How do I password protect a zip file without WinZip?

Right-click (or press and hold) a file or folder and select Properties. Select the Advanced button and select the Encrypt contents to secure data check box. Select OK to close the Advanced Attributes window, select Apply, and then select OK.


2 Answers

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

like image 120
Milad Faridnia Avatar answered Sep 22 '22 13:09

Milad Faridnia


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!

like image 44
A.Quiroga Avatar answered Sep 26 '22 13:09

A.Quiroga