android - cipher.doFinal 上的 AEADBadTagException
问题描述
我按照此指南( https://developer.android.com/codelabs/biometric-login#2 )集成了生物识别身份验证。问题是我收到了这个错误
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:502)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: javax.crypto.AEADBadTagException
at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:517)
at javax.crypto.Cipher.doFinal(Cipher.java:2055)
at com.myApp.myAppName.service.CryptographyManagerImpl.decryptData(CryptographyManager.kt:89)
CryptographyManager 第 89 行是
override fun decryptData(ciphertext: ByteArray, cipher: Cipher): String {
val plaintext = cipher.doFinal(ciphertext)
return String(plaintext, Charset.forName("UTF-8"))
}
我加密数据的方式是
override fun encryptData(plaintext: String, cipher: Cipher): CiphertextWrapper {
val ciphertext = cipher.doFinal(plaintext.toByteArray(Charset.forName("UTF-8")))
return CiphertextWrapper(ciphertext, cipher.iv)
}
Cipher
是这样初始化的
private val ENCRYPTION_BLOCK_MODE = KeyProperties.BLOCK_MODE_GCM
private val ENCRYPTION_PADDING = KeyProperties.ENCRYPTION_PADDING_NONE
private val ENCRYPTION_ALGORITHM = KeyProperties.KEY_ALGORITHM_AES
private fun getCipher(): Cipher {
val transformation = "$ENCRYPTION_ALGORITHM/$ENCRYPTION_BLOCK_MODE/$ENCRYPTION_PADDING"
return Cipher.getInstance(transformation)
}
我该如何解决这个问题?
解决方案
推荐阅读
- javascript - 节点 fs.writefile \n 未将文本添加到新行
- sql - 从行到列的透视 - Oracle SQL
- php - Ajax 仅第一次工作,第二次加载时出现 CSRF 令牌错误。如何解决这个问题?
- ldap - LDAP 搜索与 whoami
- java - “NullPointerException:需要位置。” 运行 JavaFX 项目 JAR 时,但不是从 IDE 运行时
- leaflet - 带有使用传单标签的标签的谷歌地图卫星视图不可见
- python - 通过 Selenium 和 Python 调用 webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.CHROME) 时出现 WebDriverException
- java - 这个递归代码如何改变我的列表?
- c# - c#如何知道哪个方法是构造函数
- pulseaudio - 切勿在 PulseAudio 中使用特定接收器