如何在plist iOS中加密和解密NSdata?

拉吉·帕玛(Raj Parmar)

我正在将姓名和3个电话号码保存到plist中。当我点击保存按钮时,我需要加密数据。哪一个是更方便的RNCryptor或NSData + AES。如何使用?

 -(void)saveButton
    {    

        NSArray *paths = NSSearchPathForDirectoriesInDomains
        (NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsPath = [paths objectAtIndex:0]; 
        NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"data.plist"];
        self.personName = theName.text;
        self.phoneNumbers = [[NSMutableArray alloc] initWithCapacity:3]; [phoneNumbers addObject:homePhone.text];
        [phoneNumbers addObject:workPhone.text];
        [phoneNumbers addObject:cellPhone.text];
        NSDictionary *plistDict = [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: personName, phoneNumbers, nil] forKeys:[NSArray arrayWithObjects: @"Name", @"Phones", nil]];
        NSString *error = nil;
        NSData *plistData = [NSPropertyListSerialization
                             dataFromPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&error];
        if(plistData) {
            // write plistData to our Data.plist file
            [plistData writeToFile:plistPath atomically:YES];
        }
        else
        {
            NSLog(@"Error in saveData: %@", error);
        }
    }
扎夫

有许多NSData + AES实现,其中许多存在严重缺陷。另外,许多不处理字符串和随机iv的键扩展。

如果您希望RNCryptor具有安全性,则正在积极实施它并提供良好的安全性。

现在,下一个问题是:您将如何保护钥匙?如果要研究钥匙串,就没有其他安全的方法来保存加密密钥。

但是请确保您需要执行此操作,然后查看NSData安全性选项:NSDataWritingOptions

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章