How to apply encryption on existing realm database

五迷三道 提交于 2019-12-05 21:38:15

问题


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?


回答1:


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!