Reputation: 258
How I can create Keystore and set/get my realm key. in target api 24 and 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)
}
Upvotes: 3
Views: 744
Reputation:
You can generate RSA keys in the keystore since your min sdk is set to 18. https://developer.android.com/training/articles/keystore.html
You then can use those to encrypt a generated AES key and store that in the shared preferences to use as your realm encryption key.
Upvotes: 0