Bass Pj
Bass Pj

Reputation: 41

How to remove realm file in case of missing encryption key

I'm using the unique id from an android device as the encryption key to generate RealmConfiguration.

I found an issue that the unique id changes after app was factory reset or rooted or otherwise.

That means the encryption key is not the same and when I regenerate the RealmConfiguration with new encryption key and try to get the Realm instance, then I got the error "Illegal Argument: Invalid format of Realm file."

I don't want to store the unique id as persistent in app or server. Because it would require more logic to handle a different unique id. So I want to delete Realm file to clear state and using current new encryption key.

But in Realm current version (0.85.1), I found that the deleteRealm method is required RealmConfiguration.

How to remove realm file in case of a missing encryption key, or is the only way to store the encryption key?

Upvotes: 1

Views: 1097

Answers (1)

geisshirt
geisshirt

Reputation: 2497

A Realm file is just a file on the file system, so easy way is to simply delete the file using java.io.File.delete() - maybe you can catch the exception and delete the file?

Upvotes: 0

Related Questions