目标邮编密码 &CRC [英] Objective Zip Password & CRC
问题描述
我正在使用 Objective Zip 压缩我的 iOS 应用上的一些文件.
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;
...需要一个 CRC32 值.
...requires a CRC32 value.
不是这方面的专家,并且在维基百科等上阅读了关于 CRC 的内容,我仍然不确定在此处输入什么值.
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?
感谢帮助和指导.
谢谢
推荐答案
首先,您必须计算要压缩的文件的 CRC 值:
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);
创建一个新的 Zip,添加您的文件并传递 CRC 结果:
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];
确保 zip.c (MiniZip) 中的以下行未被注释:
Be sure that you the following line in zip.c (MiniZip) is uncommented:
//#define NOCRYPT
还要检查您是否已将文件 crypt.h 添加到您的项目中.
Also check that you have added the file crypt.h to your project.
这篇关于目标邮编密码 &CRC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!