androidx_security_crypto_encrypted_prefs_key_keyset does not exist
Asked Answered
S

1

11

I am trying to edit a user's set of shared preferences in a more secure way using EncryptedSharedPreferences

private fun provideSecureSharedPreference(context: Context): SharedPreferences {
    val masterKey = MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build()
    return EncryptedSharedPreferences.create(
        context, "secret_shared_prefs", masterKey, EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
        EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
    )
}

It runs fine when I use minifyEnabled false Now I'm trying to Obfuscate the code by doing minifyEnabled true

To avoid other error, for now I have put just these lines in my proguard-rules.pro file

-dontobfuscate
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable

but the probelem is when I set minifyEnable true I am getting

java.io.FileNotFoundException: can't read keyset; the pref value __androidx_security_crypto_encrypted_prefs_key_keyset__ does not exist

I try to search old post from Stackoverflow and other channels but could not find the solution. Looking for a help thanks.

Shift answered 17/8, 2021 at 23:34 Comment(3)
did you find the solution?Circumfluous
any solution on this?Lindalindahl
meanwhile did someone find the solution?Alcaraz
N
3

I managed to get rid of this message:

java.io.FileNotFoundException: can't read keyset; the pref value androidx_security_crypto_encrypted_prefs_key_keyset does not exist

by using the 1.1.0-alpha06 version, where it says:

Updated Tink dependency to 1.8.0

So, add this to your app build.gradle:

implementation "androidx.security:security-crypto:1.1.0-alpha06"

Another option would be to use the the crypto stable 1.0.0 version and Tink 1.8.0 version, until security-crypto:1.1.0 is released:

implementation "androidx.security:security-crypto:1.0.0"
implementation "com.google.crypto.tink:tink-android:1.8.0"
Nava answered 23/6, 2023 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.