Join us at MongoDB.local London on 7 May to unlock new possibilities for your data. Use WEB50 to save 50%.
Register now >
Docs Menu
Docs Home
/ /
Realm Files

Encriptar un Realm - .NET SDK

You can encrypt your realms to ensure that the data stored to disk can't be read outside of your application. You encrypt the realm file on disk with AES-256 + SHA-2 by supplying a 64-byte encryption key when opening the realm.

Realm cifra y descifra datos de forma transparente con estándares Cifrado AES-256Utilizando los primeros 256 bits de la clave de cifrado de bits 512dada. Realm utiliza los otros 256 bits de la 512clave de cifrado de bits para validar la integridad mediante un código de autenticación de mensajes basado en hash (HMAC).

Advertencia

Do not use cryptographically-weak hashes for realm encryption keys. For optimal security, we recommend generating random rather than derived encryption keys.

Nota

Cannot Encrypt an Existing Unencrypted Realm

You must encrypt a realm the first time you open it. If you try to open an existing unencrypted realm using a configuration that contains an encryption key, Realm throws an error.

The following are key impacts to consider when encrypting a realm.

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 realm, the Realm SDK throws an error.

Las aplicaciones deben almacenar la llave de cifrado de manera segura, normalmente en el almacenamiento seguro de valores/clave de la plataforma objetivo, para que otras aplicaciones no puedan leer la clave. Por ejemplo, se puede usar MAUI Secure Storage o Xamarin Secure Storage para simplificar el acceso al almacenamiento subyacente. En última instancia, es responsabilidad del desarrollador garantizar que los atacantes no puedan acceder a la clave.

Las lecturas y escrituras en los "realms" cifrados pueden ser hasta un 10% más lentas que en los "realms" sin cifrar.

Importante

Se debe proporcionar la misma clave de cifrado cada vez que se obtiene una instancia de Realm. Si no se proporciona una clave o se especifica una clave incorrecta para un Realm cifrado, se obtendrá una excepción RealmFileAccessErrorException al llamar. GetInstance.

Puede encriptar un realm sincronizado.

If you need unique keys for each user of your application, you can use an OAuth provider (such as MAUI.Auth) and Xamarin.Auth), or use one of the Realm Authentication providers and an Authentication Trigger to create a 64-bit key and store that key in a user object.

Changed in version 11.0.0.

A partir de la versión 11.0.0 del SDK de Realm .NET, Realm admite abrir el mismo Realm cifrado en varios procesos.

In earlier versions of the Realm .NET SDK, you cannot open the same encrypted realm from multiple processes. Attempting to do so throws the error: "Encrypted interprocess sharing is currently unsupported."

Advertencia

Do not use cryptographically-weak hashes for realm encryption keys. For optimal security, we recommend generating random rather than derived encryption keys.

The following code demonstrates how to generate an encryption key and open an encrypted realm:

// Check if we already have a key stored in the platform's secure storage.
// If we don't, generate a new one:
var encryptionKey = new byte[64];
using var rng = RandomNumberGenerator.Create();
rng.GetBytes(encryptionKey);
// Store the key securely to be used next time we want to open the Realm.
// Create configuration.
var config = new RealmConfiguration
{
EncryptionKey = encryptionKey
};
// Open or create a realm with the encryption key.
var realm = Realm.GetInstance(config);

Volver

Reduce Realm File Size

En esta página