How to create a normal password-protected ZIP archive?

前端 未结 2 1849
闹比i
闹比i 2020-12-16 02:02

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 Androi

相关标签:
2条回答
  • 2020-12-16 02:13

    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!

    0 讨论(0)
  • 2020-12-16 02:18

    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.

    0 讨论(0)
提交回复
热议问题