解密核心数据

时间:2015-04-15 21:17:27

标签: objective-c sqlite core-data encryption nsmutabledictionary

警告:我不知道obj C但是已经将这个项目交给了这个任务

我成功加密了核心数据(sqlite)中的字段,但我无法使用类似的方法解密它们。下面是我的代码,它导致应用程序在获取核心数据期间中断:

NSManagedObjectContext *context = [self getContext];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:entityName inManagedObjectContext:context];

NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
[request setReturnsObjectsAsFaults:NO];
if (predicate != nil) {
    [request setPredicate:predicate];
}
NSError *error;
//the code that breaks
NSMutableDictionary *theFetch = [[context executeFetchRequest:request error:&error] mutableCopy];
return [[self decryptDictionaryData:theFetch withUserId:entityDesc.propertiesByName[@"theUnlockKey"]] mutableCopy];

decryptDictionaryData遍历字典中的每个键并解密如下:

decryptedResult = [RNDecryptor  decryptData:[[NSData alloc] initWithBase64EncodedString:value options:0]
                                       withSettings:kRNCryptorAES256Settings
                                           password:key
                                              error:&error];

0 个答案:

没有答案