請注意我們許可的“出口合規性”部分,因爲如果您位於受到美國出口限制或禁運的國家/地區,則會對使用Realm施加限制。
通過使用RealmConfiguration.Builder.encryptionKey
將512位加密密鑰(64字節)傳遞給配置,可以在磁盤上對Realm文件進行加密:
byte[] key = new byte[64];
new SecureRandom().nextBytes(key);
RealmConfiguration config = new RealmConfiguration.Builder()
.encryptionKey(key)
.build();
Realm realm = Realm.getInstance(config);
Realm使用給定的512位加密密鑰的前256位,使用標準AES-256加密透明地加密和解密數據。Realm將512位加密密鑰的其他256位用於HMAC。每次打開該Realm時,都必須提供相同的加密密鑰。有關如何在兩次運行之間安全地存儲Android KeyStore中的密鑰以使其他App無法讀取它們的示例,請參見examples/encryptionExample。