10

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!

Community
  • 1
  • 1
Lily
  • 197
  • 2
  • 2
  • 10
  • "how do I put a password on the zip file so that someone who opens it on a computer (Windows, Mac, or Ubuntu) would be able to extract the files?" do you mean WOULDN'T. you set the password so they cant open it? if you want them to "open in on a computer and extract the files" then my question is what happens when u try to double click the zip files as is (on a pc) – owen gerig Oct 14 '11 at 20:26
  • @Lily Correct. The linked post does not create a "password protected ZIP" (key phrase) but rather stores an encrypted stream inside a non-password protected ZIP. –  Oct 14 '11 at 20:26
  • 3
    I don't know if this is applicable to Android per-se (I don't even own a "smart phone" ;-), but there are such libraries for Java. See http://stackoverflow.com/questions/166340/write-a-password-protected-zip-file-in-java and http://stackoverflow.com/questions/6750569/open-password-protected-zip-in-android for links and related information. –  Oct 14 '11 at 20:28
  • @owen gerig Question is "How to create a *normal* password-protected ZIP archive?" :-) [I updated the title to reflect.] –  Oct 14 '11 at 20:28
  • @pst thanks that's what I mean... I want AUTHORIZED INDIVIDUALS to open the file with a password I give to them, but nobody else :) – Lily Oct 14 '11 at 20:34
  • @owen gerig - sorry for the confusion – Lily Oct 14 '11 at 20:34
  • @pst Also, thanks for answering my question. I did look at the first link that you gave me, but I just thought it'd be nice if Android natively supports this sort of thing :) but yeah I'll try this for now. p.s. who doesn't own a smart phone nowadays :P – Lily Oct 14 '11 at 20:41

2 Answers2

7

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

Milad Faridnia
  • 9,113
  • 13
  • 65
  • 78
2

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!

Community
  • 1
  • 1
A.Quiroga
  • 5,704
  • 6
  • 37
  • 58