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) :

//像往常一样使用共享首选项和编辑器

Update 07.02.2020 I created a bug ticket in the google bugtracker (https://issuetracker.google.com/issues/138314232) but they wont fix it...

推荐答案

此问题已从版本1.0.0-rc03修复.Clear现在工作正常.好好享受吧!

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

Kotlin相关问答推荐

KTOR';S函数`staticResources`在Kotlin本机目标上不可用

用vararg替换列表的设计弃用警告

如何处理基于枚举提前返回的 forEach 循环,Kotlin 中的一条路径除外

SpringBoot 2.5.0 对于 Jackson Kotlin 类的支持,请在类路径中添加com.fasterxml.jackson.module: jackson-module-kotlin

IntelliJ 不会根据 ktlint 的期望对 Kotlin 导入进行排序

Kotlin 解构超过五个组件

致命错误 LifecycleOwners 必须在 registerForActivityResult 开始之前调用 register

零安全的好处

Kotlin 有 array.indexOf 但我无法弄清楚如何做 array.indexOfBy { lambda }

使用 Paging 3 时保存并保留 LazyColumn 滚动位置

在java代码中使用kotlin库

Kotlin中具有多个参数的绑定适配器

大小写敏感性 Kotlin / ignoreCase

Android 上的 Kotlin:将map到list

android Room 将 Null 作为非 Null 类型返回

什么是 Kotlin 等价于 Class<?>

导航架构组件 - 未生成 DestinationFragmentArgs

Kotlin 中内部可见性修饰符的范围

使用 java lambda 调用 kotlin 函数时,Kotlin 无法访问 kotlin.jvm.functions.Function1

Android Jetpack Compose - 图像无法zoom 到框的宽度和高度