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
/ /
Manage Realm Files

Encrypt a Realm - Flutter SDK

Puede cifrar sus realms para asegurar que los datos almacenados en disco no puedan leerse fuera de su aplicación. Se debe cifrar el Realm en el disco con AES-256 + SHA-2 proporcionando una llave de cifrado de 64 bytes al momento de abrir un 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

Encripta un Realm al abrir o copia un Realm sin cifrar

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.

Alternativamente, puedes copiar los datos del realm sin cifrar a un nuevo realm cifrado usando el Realm.writeCopy() método. Consulta Copiar datos a un nuevo Realm para más información.

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

Debe pasar la misma clave de cifrado en la propiedad Configuration.encryptionKey del dominio cada vez que lo abra. La clave debe tener un 64valor de bytes. List<int>Para crear una clave que cumpla con esta especificación, la Lista debe contener exactamente 64 números enteros y todos los números enteros deben estar entre 0 y 255.

Si no proporciona una clave o especifica la clave incorrecta para un reino cifrado, el SDK de Realm genera un error.

Apps should store the encryption key securely, typically in the target platform's secure key/value storage, so that other apps cannot read the key.

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

Puede encriptar un realm sincronizado.

Realm only encrypts the data on the device and stores the data unencrypted in your Atlas data source. Any users with authorized access to the Atlas data source can read the data, but the following still applies:

  • Users must have the correct read permissions to read the synced data.

  • Data stored in Atlas is always encrypted at a volume (disk) level.

  • The transfer between client and server is always fully encrypted.

You can also enable Customer Key Management to encrypt stored Atlas data using your cloud provider's key (e.g. AWS KMS, Azure Key Vault, Google Cloud KMS).

If you need unique keys for each user of your application, you can use an OAuth provider 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 1.1.0.

A partir de la versión 1.1.0 de Realm Flutter SDK, Realm admite abrir el mismo Realm cifrado en varios procesos.

If your app uses Realm Flutter SDK version 1.1.0 or earlier, attempting to open an encrypted realm from multiple processes throws this error: Encrypted interprocess sharing is currently unsupported.

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

// Generate encryption key
final key = List<int>.generate(64, (i) => Random().nextInt(256));
final encryptedConfig = Configuration.local([Car.schema],
// Include the encryption key in the configuration
encryptionKey: key);
final encryptedRealm = Realm(encryptedConfig);

Volver

Reduce Realm File Size

En esta página