【问题标题】:how to use Encrypting Realm with key stored in KeyStore in API level 18如何在 API 级别 18 中将加密领域与存储在 KeyStore 中的密钥一起使用
【发布时间】:2017-02-05 19:18:20
【问题描述】:

如何创建密钥库并设置/获取我的领域密钥。在目标 api 24 和 minapi 18 中

Realm.init(this);
    RealmConfiguration realmConfig = new RealmConfiguration.Builder()
            .encryptionKey(getKey())
            .name("realm")
            .schemaVersion(0)
            .deleteRealmIfMigrationNeeded()
            .build();
    Realm.setDefaultConfiguration(realmConfig);

public byte[] getKey() {
    if key exist return else generate new SecureRandom().nextBytes(key)
}

【问题讨论】:

标签: android realm keystore android-keystore


【解决方案1】:

您可以在密钥库中生成 RSA 密钥,因为您的 min sdk 设置为 18。https://developer.android.com/training/articles/keystore.html

然后您可以使用这些加密生成的 AES 密钥并将其存储在共享首选项中以用作您的领域加密密钥。

【讨论】:

    猜你喜欢
    • 2023-03-21
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 1970-01-01
    • 2011-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多