请注意我们许可的“出口合规性”部分,因为如果您位于受到美国出口限制或禁运的国家/地区,则会对使用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。