如何加密iPhone上的CoreData内容 [英] How can I encrypt CoreData contents on an iPhone

查看:116
本文介绍了如何加密iPhone上的CoreData内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些我想在iPhone应用程序上静态加密的信息。我是iPhone开发的新手,有些我不太熟悉CoreData,以及它与视图的整合。我有数据作为JSON,虽然我可以很容易地把它放入SQLITE3数据库或任何其他支持数据格式。我会采取最简单的(a)加密和(b)与iPhone视图层集成。



用户将需要输入密码来解密每次应用启动时的数据。加密的目的是为了保持数据不被访问,如果用户丢失了电话。



出于加速原因,我宁愿加密和解密整个文件一次而不是加密数据库每行中的每个单独的字段。



注意:这个不是问题929744 ,其目的是让用户不要混淆或看到数据。数据在使用时应该是完全透明的。



另请注意:我愿意使用 SQLCipher 存储数据,但更喜欢使用iPhone / CoreData框架上已经存在的东西,而不是漫长的

解决方案

您可以通过使核心数据模型实体中的各个属性可转换属性,然后创建一个NSValueTransformer子类,将加密和解密数据那个财产。虽然这不是您正在寻找的全数据库解密,但它将比将整个数据库解密到内存中要低得多的内存空间。此外,它将允许解密是​​懒惰的,而不是全部在前面,所以你的应用程序将加载更快。根据所使用的加密,我甚至希望加载每个实体的磁盘上数据访问速度比属性的解密过程慢,因此在访问属性时,您不会看到性能损失太多。 / p>

像这样的可变形属性非常容易使用,因为您正常阅读和写入它们,而加密/解密在幕后。


I have some information I'd like to store statically encrypted on an iPhone application. I'm new to iPhone development, some I'm not terribly familiar with CoreData and how it integrates with the views. I have the data as JSON, though I can easily put it into a SQLITE3 database or any other backing data format. I'll take whatever is easiest (a) to encrypt and (b) to integrate with the iPhone view layer.

The user will need to enter the password to decrypt the data each time the app is launched. The purpose of the encryption is to keep the data from being accessible if the user loses the phone.

For speed reasons, I would prefer to encrypt and decrypt the entire file at once rather than encrypting each individual field in each row of the database.

Note: this isn't the same idea as Question 929744, in which the purpose is to keep the user from messing with or seeing the data. The data should be perfectly transparent when in use.

Also note: I'm willing to use SQLCipher to store the data, but would prefer to use things that already exist on the iPhone/CoreData framework rather than go through the lengthy build/integration process involved.

解决方案

You can encrypt individual properties in your Core Data model entities by making them transformable properties, then creating an NSValueTransformer subclass which will encrypt and decrypt the data for that property. While this is not the whole-database decryption that you're looking for, it will have a much lower memory footprint than decrypting an entire database into memory. Additionally, it will allow the decryption to be done lazily, rather than all up front, so your application will load much faster. Depending on the encryption used, I would even expect that the on-disk data accesses for loading each entity would be slower than the decryption process for the properties, so you won't see that much of a performance penalty when accessing the properties.

Transformable properties like this are very easy to use, because you read and write to them as normal, while the encryption / decryption goes on behind the scenes.

这篇关于如何加密iPhone上的CoreData内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆