androidx_security_crypto_encrypted_prefs_key_keyset不存在

thtygnil  于 2023-06-28  发布在  Android
关注(0)|答案(1)|浏览(240)

我正在尝试使用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
    )
}

当我使用minifyEnabled false时,它运行得很好。现在我尝试通过执行minifyEnabled true来混淆代码
为了避免其他错误,现在我只在proguard-rules.pro文件中放置了以下行

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

但问题是当我设置minifyEnable true

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

我尝试从Stackoverflow和其他渠道搜索旧帖子,但无法找到解决方案。寻求帮助,谢谢。

q9rjltbz

q9rjltbz1#

我设法摆脱了这条消息:
java.io.FileNotFoundException:无法读取键集;首选值androidx_security_crypto_encrypted_prefs_key_keyset不存在
通过使用1.1.0-alpha 06版本,它说:
将Tink依赖性更新到1.8.0
因此,将此添加到您的应用程序build.gradle

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

另一种选择是使用加密稳定1.0.0版本和Tink 1.8.0版本,直到security-crypto:1.1.0发布:

implementation "androidx.security:security-crypto:1.0.0"
implementation "com.google.crypto.tink:tink-android:1.8.0"

相关问题