Search code examples
androidrealm

Is Realm data left unencrypted if Android application crashes?


I have configured my Realm instance to use encryption. I get an instance of Realm in my activity onCreate and close it in onDestroy. If the activity crashes and onDestroy is not called, will my Realm data be left in an unencrypted state?


Solution

  • The answer I found for your question is here: https://realm.io/news/jp-simard-realm-core-database-engine/

    The way encryption is built is very similar to how it is typically done in Linux. Since we memory map the whole file, we can protect parts of that memory. If anyone tries to read from this encrypted chunk, we can throw a file system violation that we can then catch and say, “Oh, someone’s trying to access this bit of encrypted data. Decrypt only that chunk and pass it back to the user.” We can do this in a very efficient way while having very secure technology.

    So, the answer to the question is no: The data is decrypted in-memory as is being used, "on demand", not before.