Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply encryption on existing realm database

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?

like image 673
Pelle Stenild Coltau Avatar asked Jul 03 '15 10:07

Pelle Stenild Coltau


People also ask

Is realm encrypted?

Realm transparently encrypts and decrypts data with standard AES-256 encryption using the first 256 bits of the given 512-bit encryption key. Realm uses the other 256 bits of the 512-bit encryption key to validate integrity using a hash-based message authentication code (HMAC) .

Can we encrypt database?

Transparent data encryption (TDE) encrypts SQL Server, Azure SQL Database, and Azure Synapse Analytics data files. This encryption is known as encrypting data at rest. To help secure a database, you can take precautions like: Designing a secure system.


1 Answers

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.

like image 134
jpsim Avatar answered Sep 21 '22 22:09

jpsim