我正在尝试使用masterKey来加密共享的首选项。然而,有时我的用户会因为来自keystore的invalidKeyException而崩溃。我不能在本地重现这个=\
java.security.KeyStoreException: the master key android-keystore://_androidx_security_master_key_ exists but is unusable
Caused by: java.security.InvalidKeyException: Keystore cannot load the key with ID: _androidx_security_master_key_你知道为什么会发生这种情况吗?
val masterKey = MasterKey.Builder(context)
.setKeyGenParameterSpec(
KeyGenParameterSpec.Builder(
MasterKey.DEFAULT_MASTER_KEY_ALIAS,
PURPOSE_ENCRYPT or PURPOSE_DECRYPT
)
.setBlockModes(BLOCK_MODE_GCM)
.setEncryptionPaddings(ENCRYPTION_PADDING_NONE)
.setKeySize(MasterKey.DEFAULT_AES_GCM_MASTER_KEY_SIZE)
.build()
)
.build()
securePrefs = EncryptedSharedPreferences.create(
context,
PREFERENCES,
masterKey,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)发布于 2021-01-28 14:02:37
这个问题也已经详细地报告给了Google bug追踪器。跟踪那里的讨论可能会更好。
https://stackoverflow.com/questions/65137119
复制相似问题