Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application Crash Using EncryptedSharedPreferences - Version : security-crypto-ktx:1.1.0-alpha06 #39

Closed
mmfaragallah opened this issue Jul 18, 2024 · 4 comments

Comments

@mmfaragallah
Copy link

Application crashes while using EncryptedSharedPreferences.create

As following:

val sharedPreferences = EncryptedSharedPreferences.create(
context,
SECURE_PREF_FILE_NAME,
masterKey,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
)

Version used:

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

Device details attached.
PHOTO-2024-07-17-12-02-24

Android 13 .

Stacktrace.

Kindly, how to avoid application crash?

Thanks.

FATAL EXCEPTION: main
Process: com.qatar.mwani.mwanina, PID: 14944
javax.crypto.AEADBadTagException
at android.security.keystore2.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:617)
at javax.crypto.Cipher.doFinal(Cipher.java:2114)
at com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.decryptInternal(AndroidKeystoreAesGcm.java:118)
at com.google.crypto.tink.integration.android.AndroidKeystoreAesGcm.decrypt(AndroidKeystoreAesGcm.java:101)
at com.google.crypto.tink.KeysetHandle.decrypt(KeysetHandle.java:919)
at com.google.crypto.tink.KeysetHandle.readWithAssociatedData(KeysetHandle.java:804)
at com.google.crypto.tink.KeysetHandle.read(KeysetHandle.java:785)
at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readMasterkeyDecryptAndParseKeyset(AndroidKeysetManager.java:381)
at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:297)
at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:169)
at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:130)
at com.qatar.mwani.mwanina.features.login.domain.usecase.SaveUserCredentialUseCaseImpl.invoke(SaveUserCredentialUseCaseImpl.kt:22)
at com.qatar.mwani.mwanina.features.login.presentation.viewmodel.LoginViewModel$whenLoginButtonClicked$1.invokeSuspend(LoginViewModel.kt:77)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:604)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@328d0cf, Dispatchers.Main.immediate]
Caused by: android.security.KeyStoreException: Signature/MAC verification failed (internal Keystore code: -30 message: In KeystoreOperation::finish

                                                                                                Caused by:
                                                                                                    0: In finish: KeyMint::finish failed.
                                                                                                    1: Error::Km(ErrorCode(-30))) (public error code: 10 internal Keystore code: -30)
                                                                                                	at android.security.KeyStore2.getKeyStoreException(KeyStore2.java:418)
                                                                                                	at android.security.KeyStoreOperation.handleExceptions(KeyStoreOperation.java:78)
                                                                                                	at android.security.KeyStoreOperation.finish(KeyStoreOperation.java:128)
                                                                                                	at android.security.keystore2.KeyStoreCryptoOperationChunkedStreamer$MainDataStream.finish(KeyStoreCryptoOperationChunkedStreamer.java:228)
                                                                                                	at android.security.keystore2.KeyStoreCryptoOperationChunkedStreamer.doFinal(KeyStoreCryptoOperationChunkedStreamer.java:181)
                                                                                                	at android.security.keystore2.AndroidKeyStoreAuthenticatedAESCipherSpi$BufferAllOutputUntilDoFinalStreamer.doFinal(AndroidKeyStoreAuthenticatedAESCipherSpi.java:396)
                                                                                                	at android.security.keystore2.AndroidKeyStoreCipherSpiBase.engineDoFinal(AndroidKeyStoreCipherSpiBase.java:609)
                                                                                                	... 22 more
@mmfaragallah
Copy link
Author

@juergw @tholenst Appreciate your help on this issue, thanks.

@juergw
Copy link
Contributor

juergw commented Jul 23, 2024

See discussion on #23

@mmfaragallah
Copy link
Author

mmfaragallah commented Jul 27, 2024 via email

@juergw
Copy link
Contributor

juergw commented Aug 15, 2024

Sorry, we can't help you with this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants