I have an iOS app that use a non-encrypted realm database.
Now I would like to apply encryption on that database.
Can I just set an encryption key using:
Realm.setEncryptionKey(key, forPath: Realm.defaultPath)
and then realm will encrypt the existing database?
Or do I need to create a new realm database file with encryption and then move the data in the existing database to the new encrypted database?
You'll have to create an encrypted copy of the unencrypted Realm file, which you can do by using Realm().writeCopyToPath(_:encryptionKey:) and then you can use the encrypted file at the new location.
来源:https://stackoverflow.com/questions/31204890/how-to-apply-encryption-on-existing-realm-database