First Activity
try {
masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);
sharedPreferences = EncryptedSharedPreferences.create(
"secret_shared_prefs",
masterKeyAlias,
getApplicationContext(),
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
);
} catch (GeneralSecurityException | IOException e) {
e.printStackTrace();
}
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("memberID", response.body().get(0).getMemberID().toString()).commit();
Second Activity
SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("secret_shared_prefs", MODE_PRIVATE);
sharedPreferences.getString("memberID", "unknown");
Within the same activity, getSharedPreferences() works as expected. When trying to access the preferences in another activity using this code, it always returns the default value. It seems there is a problem with decryption.