当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - ziparchive password detection

问题描述:

Does anyone know a way to detect if a zip file has a pasword set when trying to unzip with the library ZipArchive?

The code:

[zip UnzipOpenFile:unzipFilename Password:zipPassword]

will:

  • unzip files with a password when zipPassword is set.

  • unzip files without a password when zipPassword is nil

BUT

if directing a user to select a zip file I need to know whether to prompt the user for a password if the zip file has one otherwise all files in the zip are created but with zero length.

Seems messy to do this, check for zero length and if so prompt user for password for another try?

Surely there must be a way to tell if the zip file in question has a password?

网友答案:

I am using ZipArchive utility to import zipped file in Objective C application. Part of the code is

if ([za UnzipOpenFile:[url path] Password:@"XYZ"]){

     BOOL ret = [za UnzipFileTo: documentsDirectory overWrite: YES];

I find that my password protected zipped file gets unzipped by above code even without using a password ( using [za UnzipOpenFile:[url path]] ) or even when a wrong password as above is given.

The zipped file was created using zip -e option on Mac. Is there any flag that needs to be set up to make password detection work ?

分享给朋友:
您可能感兴趣的文章:
随机阅读: