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

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

问题描述

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



用户将需要输入密码解密每次应用程序启动时的数据。加密的目的是在用户丢失电话时保持数据的可访问性。



由于速度的原因,我宁愿加密和解密整个文件



注意:此不是相同的概念, http://stackoverflow.com/questions/929744/encrypting-sqlite-database-file-in-iphone-os\">Question 929744 ,其中的目的是防止用户弄乱或看到数据。在使用时,数据应该完全透明。



还要注意:我愿意使用 SQLCipher 来存储数据,但是更喜欢使用iPhone / CoreData框架上已经存在的东西,而不是通过冗长的

您可以通过将您的Core Data模型实体中的单个属性加密,使它们 https://developer.apple.com/library/ios/samplecode/PhotoLocations/Introduction/Intro.htmlrel =nofollow noreferrer>可变属性,然后创建一个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天全站免登陆