NSFetchedResultsController不对加密属性进行排序 [英] NSFetchedResultsController not sorting on encrypted attributes

查看:129
本文介绍了NSFetchedResultsController不对加密属性进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用可变类型对我的Core Data模型中的属性进行加密,但是一旦数据被持久化到sqlite数据库中,就会遇到很多问题。我的Core Data的主要应用是存储一些用户相关的数据,并按照名字,姓氏等重新排序,然后在表视图中使用第一个/姓的第一个字母作为节头。看来,加密干扰的结果,因为我没有回来,当我尝试使用NSFetchedResultsController使用lastName作为排序描述符获取请求。我得到以下错误:

I am trying to encrypt the attributes in my Core Data model using the transformable type but am experiencing a lot of issues trying to fetch back results once data has been persisted to the sqlite db. My main application for Core Data is to store some user related data and fetch it back again sorted by first name, last name etc and then display it in a table view using the first letter of first/last name as the section header. It seems that the encryption is interfering with the results because i get nothing back when i try to do fetch request with NSFetchedResultsController using the lastName as a sort descriptor. I get the following error:

CoreData: error: (NSFetchedResultsController) The fetched object at index X has an out of order section name 'S. Objects must be sorted by section name'

进行排序Ive花了很多时间调查这个问题没有用。有谁知道什么问题,以及如何解决它?在变压器解密数据后,是否有可能在db上做排序的方法?或者有一种方法可能回到原始数据,然后排序它在NSFetchedResultsController的实例中的数据?

Ive spent a lot of time investigating this issue to no avail. Does anybody know what the issue might be and how to get around it? Is there perhaps a way to do the sort on the db after the transformer decrypts the data? Or is there a way to maybe get back the raw data and then sort it after i have the data in an instance of the NSFetchedResultsController?

我使用这个来加密核心数据属性:

I used this source to encrypt the core data attribute:

推荐答案

您描述的错误发生,因为排序发生在数据库中的加密数据,但 NSFetchedResultsController

The error you describe happens because sorting happens on the encrypted data in the database, but the NSFetchedResultsController later works on unencrypted data, and complains because the data is not sorted correctly for the section name.

要对数据库进行排序,您需要在数据库中进行排序。

To sort inside the db you would have to provide enough unencrypted info to sort, and to keep that info up-to-date.

例如,对于按名字排序,可以存储未加密的属性

For example, for sorting by first name, you could store an unencrypted attribute firstNameSection which contains the first letter of the firstName, and an attribute firstNameSortInfo which contains the position of that name for each index (for example "Aaron"=0, "Abby"=1, etc.

c $ c> firstNameSection firstNameSortInfo 用于排序, firstNameSection sectionNameKeyPath 。这种方法至少有两个缺点:

Then you could use firstNameSection and firstNameSortInfo for sorting, and firstNameSection as sectionNameKeyPath. This approach has (at least) two drawbacks:


  1. 你必须保留 firstNameSortInfo 更新,这将需要更多的写入,而你需要更多的写,和 firstNameSortInfo 排序将必须在内存中完成未加密的数据)。

  2. 有关加密数据的一些信息可能是潜在攻击者已知的,这可能会削弱加密。

  1. You would have to keep the firstNameSortInfo up-to-date, and this would need more writes than you may like, and the firstNameSortInfo sorting would have to be done in-memory (as it is done on unencrypted data).
  2. Some info about the encrypted data may be known to a potential attacker, which may weaken the encryption.

这篇关于NSFetchedResultsController不对加密属性进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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