0

Is there anyway one can override NSPersistentDocument to encrypt and require a password to open the file? In other words, is it possible to encrypt a document as a whole with a user provided password? I've looked into solutions and it seems the only way is to actually encrypt the CoreData data itself independently, however that would make it impossible to use a NSPredicate to filter a NSFetchRequest since the data would be encrypted. An alternative would be using Realm which has an encryption key, but that only encrypts the Realm data, leaving all other data in the document unencrypted.

Andre Yonadam
  • 964
  • 1
  • 13
  • 30

2 Answers2

1

You can encrypt CoreData objects, and by creating transient (in memory only) cleartext fields on reading, you can use NSPredicate to filter NSFetchRequest on those cleartext fields. See here for a sample of the encrypt/decrypt code: https://github.com/michaelrourke/EncryptedCoreData

MichaelR
  • 1,681
  • 15
  • 28
0

Have a look at the document for NSPersistentStore and its two abstract subclasses, NSAtomicStore and NSIncrementalStore. If you make a custom subclass of one of these, you can customize the backend that Core Data writes to.

Charles Srstka
  • 16,665
  • 3
  • 34
  • 60