【问题标题】:How to unzip AES encrypted files in iOS如何在 iOS 中解压 AES 加密文件
【发布时间】:2013-09-27 06:39:23
【问题描述】:

我是 Objective-C 的初学者,需要你的帮助。

在 iOS 中,我需要解压缩使用 AES 256 方法加密的文件。

在这个答案中https://stackoverflow.com/a/10489305/2822169Nathan Moinvaziri 写了关于使用这个库的文章:https://github.com/nmoinvaz/minizip

我正在尝试这样做:

#import "unzip.h"

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *path = [paths objectAtIndex:0];
    NSString *zipPath = [path stringByAppendingPathComponent:@"myFile.zip"];   // this file exists there 100%

    unzFile *uf = unzOpen64((__bridge const void *)(zipPath));  // but here uf returns 0x00000000
    unzOpenCurrentFilePassword(uf, (__bridge const void *)(@"myPassword"));
}

请告诉我有什么问题?

谢谢!

【问题讨论】:

    标签: ios objective-c encryption zip aes


    【解决方案1】:

    这可能是unZip. 的最佳库

    下载它并将其添加到您的项目中,

    #import "ZipArchive.h" // in your ".m" file
    

    并编写如下代码

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];
    
    NSString *basepath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"resources.zip"]];
        [self.responseData  writeToFile:basepath  atomically:YES];
    
        ZipArchive* za = [[ZipArchive alloc] init];
        if( [za UnzipOpenFile:[NSString stringWithFormat:@"%@",basepath]] )
        {
            BOOL ret = [za UnzipFileTo:[GeneralClass getDocumentDirectory]  overWrite:YES];
            if(!ret)
                NSLog(@"problem while loading data..");
            [za UnzipCloseFile];
        }
    
        NSFileManager *fileManager = [NSFileManager defaultManager];
        [fileManager removeItemAtPath:basepath error:NULL];
    
        basepath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"response.txt"]];
        NSString* response = [NSString stringWithContentsOfFile:basepath encoding:NSUTF8StringEncoding error:NULL];
        NSMutableDictionary *detailRequestData = [[NSMutableDictionary alloc] init];
        detailRequestData = [response JSONValue];
        [fileManager removeItemAtPath:basepath error:NULL];
    
     NSLog(@"I Got Data%@", detailRequestData); /// see in consol 
    

    【讨论】:

    • 谢谢。但是你确定这个库支持 zip 文件中的 AES 加密吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-18
    • 2013-05-21
    • 2013-07-10
    • 1970-01-01
    相关资源
    最近更新 更多