android.security.KeyStoreException: Signature/MAC 验证失败

android.security.KeyStoreException: Signature/MAC verification failed

我在尝试注册应用程序时遇到错误。当我输入我的 phone 号码并注册时,它会进入 otp 验证但没有得到 otp。但它给了我一个错误,说 problem to get safety net token:7。请帮助我度过难关。之前可以正常工作,但现在出现错误。

我在 firebase 设置中也添加了 sha-1 和 sha-256。 我还添加了 google-service.jsons 文件。

错误:

javax.crypto.AEADBadTagException
    at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:51 
7)
    at javax.crypto.Cipher.doFinal(Cipher.java:2113)
    at com.google.android.gms.internal.firebase-auth-api.zzdt.zzd(com.google.firebase:firebase-auth@@20.0.4:7)
    at com.google.android.gms.internal.firebase-auth-api.zzdt.zzb(com.google.firebase:firebase-auth@@20.0.4:1)
    at com.google.android.gms.internal.firebase-auth-api.zzau.zzi(com.google.firebase:firebase-auth@@20.0.4:5)
    at com.google.android.gms.internal.firebase-auth-api.zzdr.zzi(com.google.firebase:firebase-auth@@20.0.4:1)
    at com.google.android.gms.internal.firebase-auth-api.zzdr.zzd(com.google.firebase:firebase-auth@@20.0.4:2)
    at com.google.firebase.auth.internal.zzk.<init>(com.google.firebase:firebase-auth@@20.0.4:7)
    at com.google.firebase.auth.internal.zzk.zza(com.google.firebase:firebase-auth@@20.0.4:3)
    at com.google.firebase.auth.internal.RecaptchaActivity.zzd(com.google.firebase:firebase-auth@@20.0.4:9)
    at com.google.android.gms.internal.firebase-auth-api.zztw.<init>(com.google.firebase:firebase-auth@@20.0.4:13)
    at com.google.firebase.auth.internal.RecaptchaActivity.onResume(com.google.firebase:firebase-auth@@20.0.4:43)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1465)
    at android.app.Activity.performResume(Activity.java:8223)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4779)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4832)
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:190)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:105)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:213)
    at android.app.ActivityThread.main(ActivityThread.java:8178)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
 Caused by: android.security.KeyStoreException: Signature/MAC verification failed
    at android.security.KeyStore.getKeyStoreException(KeyStore.java:1316)
    at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:224)
    at android.security.keystore.AndroidKeyStoreAuthenticatedAESCipherSpi$BufferAllOutputUntilDoFinalStreamer.doFinal(AndroidKeyStoreAuthenticatedAESCipherSpi.java:373)
    at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
    at javax.crypto.Cipher.doFinal(Cipher.java:2113) 
    at com.google.android.gms.internal.firebase-auth-api.zzdt.zzd(com.google.firebase:firebase-auth@@20.0.4:7) 
    at com.google.android.gms.internal.firebase-auth-api.zzdt.zzb(com.google.firebase:firebase-auth@@20.0.4:1) 
    at com.google.android.gms.internal.firebase-auth-api.zzau.zzi(com.google.firebase:firebase-auth@@20.0.4:5) 
    at com.google.android.gms.internal.firebase-auth-api.zzdr.zzi(com.google.firebase:firebase-auth@@20.0.4:1) 
    at com.google.android.gms.internal.firebase-auth-api.zzdr.zzd(com.google.firebase:firebase-auth@@20.0.4:2) 
    at com.google.firebase.auth.internal.zzk.<init>(com.google.firebase:firebase-auth@@20.0.4:7) 
    at com.google.firebase.auth.internal.zzk.zza(com.google.firebase:firebase-auth@@20.0.4:3) 
    at com.google.firebase.auth.internal.RecaptchaActivity.zzd(com.google.firebase:firebase-auth@@20.0.4:9) 
    at com.google.android.gms.internal.firebase-auth-api.zztw.<init>(com.google.firebase:firebase-auth@@20.0.4:13) 
    at com.google.firebase.auth.internal.RecaptchaActivity.onResume(com.google.firebase:firebase-auth@@20.0.4:43) 
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1465) 
    at android.app.Activity.performResume(Activity.java:8223) 
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4779) 
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4832) 
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) 
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:190) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:105) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:213) 
    at android.app.ActivityThread.main(ActivityThread.java:8178) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) 
W/zzds: cannot decrypt keyset: 
javax.crypto.AEADBadTagException
    at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:517)
    at javax.crypto.Cipher.doFinal(Cipher.java:2113)
    at com.google.android.gms.internal.firebase-auth-api.zzdt.zzd(com.google.firebase:firebase-auth@@20.0.4:7)
    at com.google.android.gms.internal.firebase-auth-api.zzdt.zzb(com.google.firebase:firebase-auth@@20.0.4:4)
    at com.google.android.gms.internal.firebase-auth-api.zzau.zzi(com.google.firebase:firebase-auth@@20.0.4:5)
    at com.google.android.gms.internal.firebase-auth-api.zzdr.zzi(com.google.firebase:firebase-auth@@20.0.4:1)
    at com.google.android.gms.internal.firebase-auth-api.zzdr.zzd(com.google.firebase:firebase-auth@@20.0.4:2)
    at com.google.firebase.auth.internal.zzk.<init>(com.google.firebase:firebase-auth@@20.0.4:7)
    at com.google.firebase.auth.internal.zzk.zza(com.google.firebase:firebase-auth@@20.0.4:3)
    at com.google.firebase.auth.internal.RecaptchaActivity.zzd(com.google.firebase:firebase-auth@@20.0.4:9)
    at com.google.android.gms.internal.firebase-auth-api.zztw.<init>(com.google.firebase:firebase-auth@@20.0.4:13)
    at com.google.firebase.auth.internal.RecaptchaActivity.onResume(com.google.firebase:firebase-auth@@20.0.4:43)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1465)
    at android.app.Activity.performResume(Activity.java:8223)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4779)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4832)
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:190)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:105)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:213)
    at android.app.ActivityThread.main(ActivityThread.java:8178)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
 Caused by: android.security.KeyStoreException: Signature/MAC verification failed
    at android.security.KeyStore.getKeyStoreException(KeyStore.java:1316)
    at android.security.keystore.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:224)
    at android.security.keystore.AndroidKeyStoreAuthenticatedAESCipherSpi$BufferAllOutputUntilDoFinalStreamer.doFinal(AndroidKeyStoreAuthenticatedAESCipherSpi.java:373)
    at android.security.keystore.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:506)
    at javax.crypto.Cipher.doFinal(Cipher.java:2113) 
    at com.google.android.gms.internal.firebase-auth-api.zzdt.zzd(com.google.firebase:firebase-auth@@20.0.4:7) 
    at com.google.android.gms.internal.firebase-auth-api.zzdt.zzb(com.google.firebase:firebase-auth@@20.0.4:4) 
    at com.google.android.gms.internal.firebase-auth-api.zzau.zzi(com.google.firebase:firebase-auth@@20.0.4:5) 
    at com.google.android.gms.internal.firebase-auth-api.zzdr.zzi(com.google.firebase:firebase-auth@@20.0.4:1) 
    at com.google.android.gms.internal.firebase-auth-api.zzdr.zzd(com.google.firebase:firebase-auth@@20.0.4:2) 
    at com.google.firebase.auth.internal.zzk.<init>(com.google.firebase:firebase-auth@@20.0.4:7) 
    at com.google.firebase.auth.internal.zzk.zza(com.google.firebase:firebase-auth@@20.0.4:3) 
    at com.google.firebase.auth.internal.RecaptchaActivity.zzd(com.google.firebase:firebase-auth@@20.0.4:9) 
    at com.google.android.gms.internal.firebase-auth-api.zztw.<init>(com.google.firebase:firebase-auth@@20.0.4:13) 
    at com.google.firebase.auth.internal.RecaptchaActivity.onResume(com.google.firebase:firebase-auth@@20.0.4:43) 
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1465) 
    at android.app.Activity.performResume(Activity.java:8223) 
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4779) 
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4832) 
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:52) 
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:190) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:105) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2386) 
    at android.os.Handler.dispatchMessage(Handler.java:107) 
    at android.os.Looper.loop(Looper.java:213) 
    at android.app.ActivityThread.main(ActivityThread.java:8178) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101) 
E/FirebearCryptoHelper: Exception encountered during crypto setup:
Protocol message contained an invalid tag (zero).
KeysetManager failed to initialize - unable to get Public key
E/RecaptchaActivity: Could not generate an encryption key for reCAPTCHA - cancelling flow.
W/System: Ignoring header X-Firebase-Locale because its value was null.
E/zzf: Failed to get reCAPTCHA token with error [An internal error has 
occurred. [ Failed to generate/retrieve public encryption key for reCAPTCHA 
flow. ]]- calling backend without app verification

好吧,我几乎没有经历过。最后我明白了 mac 验证失败的错误。这是因为,我们需要启用 android 设备验证。为此,我遵循了以下步骤。

  1. 转到https://console.cloud.google.com/

2.Type 您的 firebase 项目名称-> select 您的项目-> 弹出您的项目并单击

  1. 点击API和服务(左侧导航栏)

  2. select library->向下滚动并点击mobile->点击android device verification->enable api

  3. 清理并重建您的应用程序-> 运行-> 完美运行。

我在下面添加了依赖:

实施'androidx.security:security-crypto:1.1.0-alpha02'

实现“androidx.browser:浏览器:1.2.0”

现在它对我来说工作得很好。它也可能对其他人有所帮助。