Skip to content

Commit

Permalink
Small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
cbullinger committed Nov 9, 2023
1 parent 7fea56d commit 32e6a45
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class EncryptARealmTest : RealmTest() {
.build()
// Open the realm with the configuration
val realm = Realm.open(config)
Log.v("Successfully opened encrypted realm:" + realm.configuration.name)
Log.v("Successfully opened encrypted realm: ${realm.configuration.name}")
// :remove-start:
assertEquals(generatedKey, realm.configuration.encryptionKey)
realm.close()
Expand All @@ -64,15 +64,15 @@ class EncryptARealmTest : RealmTest() {
runBlocking {
val user = app.login(Credentials.anonymous())
// :snippet-start: encrypt-synced-realm
val config = SyncConfiguration.Builder(user, setOf(Frog::class))
val syncConfig = SyncConfiguration.Builder(user, setOf(Frog::class))
.initialSubscriptions { realm ->
add(realm.query<Frog>())
}
// Specify the encryption key
.encryptionKey(generatedKey)
.build()
val realm = Realm.open(config)
Log.v("Successfully opened encrypted realm: ${realm.configuration}")
val realm = Realm.open(syncConfig)
Log.v("Successfully opened encrypted realm: ${realm.configuration.name}")
// :snippet-end:
assertEquals(generatedKey, realm.configuration.encryptionKey)
realm.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ runBlocking {
.build()
// Open the realm with the configuration
val realm = Realm.open(config)
Log.v("Successfully opened encrypted realm:" + realm.configuration.name)
Log.v("Successfully opened encrypted realm: ${realm.configuration.name}")
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
val config = SyncConfiguration.Builder(user, setOf(Frog::class))
val syncConfig = SyncConfiguration.Builder(user, setOf(Frog::class))
.initialSubscriptions { realm ->
add(realm.query<Frog>())
}
// Specify the encryption key
.encryptionKey(generatedKey)
.build()
val realm = Realm.open(config)
Log.v("Successfully opened encrypted realm: ${realm.configuration}")
val realm = Realm.open(syncConfig)
Log.v("Successfully opened encrypted realm: ${realm.configuration.name}")
50 changes: 21 additions & 29 deletions source/sdk/kotlin/realm-database/realm-files/encrypt-a-realm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ open an encrypted local realm:
Encrypt a Synced Realm
----------------------

You can also encrypt a :ref:`synced realm <kotlin-open-a-synced-realm>`, similar
to encrypting a local realm. Refer to the :ref:`<kotlin-encryption-and-device-sync>`
section on this page for more information.
You can encrypt a :ref:`synced realm <kotlin-open-a-synced-realm>`, similar
to encrypting a local realm.

To encrypt a synced realm, pass your encryption key to the
`encryptionKey <{+kotlin-sync-prefix+}io.realm.kotlin.mongodb/-app-configuration/encryption-key.html>`__
Expand All @@ -60,13 +59,25 @@ The following code demonstrates how to open an encrypted synced realm:
:language: kotlin
:emphasize-lines: 5-6

Considerations
--------------
Encryption and Atlas Device Sync
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. include:: /includes/encrypt-atlas-device-sync.rst

The following are key impacts to consider when encrypting a realm.
If you need unique keys for each user of your application, you can use an OAuth provider or
use one of the :ref:`Realm authentication providers <users-and-authentication>`
and an :ref:`authentication trigger<authentication-triggers>`
to create a 64-bit key and store that key in a :ref:`user object <user-objects>`.

Encrypt App Metadata
~~~~~~~~~~~~~~~~~~~~

You can also encrypt the App Services App metadata that Realm stores on the device.

To learn more, refer to :ref:`<kotlin-encrypt-app-metadata>`.

Store & Reuse Keys
~~~~~~~~~~~~~~~~~~
------------------

You **must** pass the same encryption key every time you open the encrypted realm.
If you don't provide a key or specify the wrong key for an encrypted
Expand All @@ -82,12 +93,12 @@ It is the developer's responsibility to ensure that attackers cannot access the
key.

Performance Impact
~~~~~~~~~~~~~~~~~~
------------------

Reads and writes on encrypted realms can be up to 10% slower than unencrypted realms.

Access an Encrypted Realm from Multiple Processes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Access Encrypted Realm from Multiple Processes
----------------------------------------------

.. versionchanged:: 10.8.0

Expand All @@ -97,22 +108,3 @@ the same encrypted realm in multiple processes.
If your app uses Realm Kotlin SDK version 10.7.1 or earlier, attempting to
open an encrypted realm from multiple processes throws this error:
``Encrypted interprocess sharing is currently unsupported.``

.. _kotlin-encryption-and-device-sync:

Encryption and Atlas Device Sync
--------------------------------

.. include:: /includes/encrypt-atlas-device-sync.rst

If you need unique keys for each user of your application, you can use an OAuth provider or
use one of the :ref:`Realm authentication providers <users-and-authentication>`
and an :ref:`authentication trigger<authentication-triggers>`
to create a 64-bit key and store that key in a :ref:`user object <user-objects>`.

Encrypt App Metadata
~~~~~~~~~~~~~~~~~~~~

You can encrypt the App Services App metadata that Realm stores on the device.

To learn more, refer to :ref:`<kotlin-encrypt-app-metadata>`.

0 comments on commit 32e6a45

Please sign in to comment.