I use the EncryptedSharedPreferences from the androidx.security:security-crypto:1.0.0-alpha02 lib to store some Tokens. If i use prefs.edit().remove("token")).apply()
or prefs.edit().remove("token")).commit()
the token is removed. But if i try to clear the prefs at once with the clear()
method nothing happens.
This call: prefs.edit().clear().commit()
even returns false
.
I get the EncryptedSharedPreferences by using this method:
private fun getPrefs(): SharedPreferences {
val masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC)
return EncryptedSharedPreferences.create(
"myPrefs",
masterKeyAlias,
context,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)
}
Do i have to clear the EncryptedSharedPreferences in some other way?
The documentation says (https://developer.android.com/reference/androidx/security/crypto/EncryptedSharedPreferences) :
// use the shared preferences and editor as you normally would SharedPreferences.Editor editor = sharedPreferences.edit();
Update 07.02.2020 I created a bug ticket in the google bugtracker (https://issuetracker.google.com/issues/138314232) but they wont fix it...
EncrypedSharedPreferences
is a new api, it might be a bug. Check out the issue tracker: issuetracker.google.com/issues?q=EncryptedSharedPreferences if there is no bug, then create a ticket for it. – Scientist