1

I'm using Objective Zip to zip-up some files on my iOS app.

I want to protect them with a password and note the call...

- (ZipWriteStream *) writeFileInZipWithName:(NSString *)fileNameInZip fileDate:(NSDate *)fileDate compressionLevel:(ZipCompressionLevel)compressionLevel password:(NSString *)password crc32:(NSUInteger)crc32;

...requires a CRC32 value.

Not being expert on this, and having read-up about CRC on wikipedia etc., I'm still not sure what value to enter here.

Can it be zero? Should it be the byte-count of the file? Any random number?

Help and guidance appreciated.

Thanks

Fittoburst
  • 2,215
  • 2
  • 21
  • 33
  • Did you find the answer to this question? – SAHM Nov 11 '14 at 21:41
  • Sadly, no. Do you have an answer? – Fittoburst Nov 11 '14 at 22:16
  • No, trying to figure it out. Thanks for answering so quickly. – SAHM Nov 12 '14 at 01:59
  • Any enlightenment would be appreciated if you do get anywhere. There must be someone out there who can help!!! – Fittoburst Nov 12 '14 at 09:44
  • I ended up using ZipArchive. I do find that it is lacking, but that Objective-Zip is also lacking especially as pertains to catching NSException and using ARC. Ultimately I plan on transitioning away from using zip files, but for now, ZipArchive is what I will use in the short term. Sorry I couldn't be of more help. – SAHM Nov 13 '14 at 04:47
  • I made a fork of Objective-Zip named UnzipKit, which might help you out - it's easier to use, and you don't need to provide CRCs unless you want to. https://github.com/abbeycode/UnzipKit – Dov Jun 16 '15 at 18:14

1 Answers1

0

At first you have to calculate the CRC value for your file you want to zip:

NSData *data = [[NSData alloc] initWithContentsOfFile:@"/path/to/your/file/to/zip"];
unsigned long result = crc32(0, data.bytes, (unsigned int)data.length);

Create a new Zip, add your file and pass the CRC result:

ZipFile *zipFile= [[ZipFile alloc] initWithFileName:@"/tmp/File.zip" mode:ZipFileModeCreate];
ZipWriteStream *stream= [zipFile writeFileInZipWithName:@"File.name" fileDate:[NSDate date] compressionLevel:ZipCompressionLevelDefault password:@"your_password"] crc32:result];
[stream writeData:data];
[stream finishedWriting];

[zipFile close];

Be sure that you the following line in zip.c (MiniZip) is uncommented:

//#define NOCRYPT

Also check that you have added the file crypt.h to your project.

Matt
  • 448
  • 5
  • 16
  • 1
    Following these instructions did not solve the problem. I can't unzip the resulting zip file with wrong password error. Any ideas? Please note that I am zipping more files in the same archive. – Donnit Mar 11 '15 at 17:05
  • Does it work if you zip only one file? Which software do you use for unzipping? – Matt Mar 13 '15 at 15:46
  • I will try with a single file. For unzipping I use "The Unarchiver" for Mac. But I also tried shell utilities on linux and mac... – Donnit Mar 14 '15 at 12:38