Example below:-
try {
String mainKey = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);
SharedPreferences sharedPreferences = EncryptedSharedPreferences.create(
"example",
mainKey,
this,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
);
@SuppressLint("CommitPrefEdits")
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt("id", 23);
editor.apply();
Log.e("tag", "id: " + sharedPreferences.getInt("id", 0));
} catch (GeneralSecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Comments
Post a Comment