Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete EncryptedSharedPreferences with clear() not working

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...

like image 495
elpatricko Avatar asked Jul 25 '19 13:07

elpatricko


1 Answers

This issue fixed from version 1.0.0-rc03. Clear is working fine now. Enjoy!

Refer release note: https://developer.android.com/jetpack/androidx/releases/security#security-crypto-1.0.0-rc03

like image 123
Jeevanandham S Avatar answered Oct 27 '22 09:10

Jeevanandham S