是的,您必须使用新的加密密钥复制Realm文件.该方法称为writeEncryptedCopyTo():https://realm.io/docs/java/latest/api/io/realm/Realm.html#writeEncryptedCopyTo-java.io.File-byte : A-
像下面这样的东西应该工作:
RealmConfiguration config1 = new RealmConfiguration.Builder(context)
.name("old-name")
.encryptionKey(getOldKey())
.build()
Realm realm = Realm.getInstance(config1);
realm.writeEncryptedCopyTo(new File(context.getFilesDir(), "new-name"), getNewKey());
realm.close();
RealmConfiguration config2 = new RealmConfiguration.Builder(context)
.name("new-name")
.encryptionKey(getNewKey())
.build()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1839 次 |
| 最近记录: |