Crash with exception - Failed to load generated key pair from keystore
See original GitHub issueWe are seeing the following exception in our app causing the app to crash during sign-in. Is it a known issue? Is there a workaround ?
This crash is happening across all Android versions and device models, however the number of crashes are very high on OnePlus & Xiaomi devices with Android 7.1.
### java.security.ProviderException: Failed to load generated key pair from keystore
at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.loadKeystoreKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:518)
at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.generateKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:470)
at java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:699)
at com.microsoft.aad.adal.StorageHelper.generateKeyPairFromAndroidKeyStore(StorageHelper.java:414)
at com.microsoft.aad.adal.StorageHelper.getKeyOrCreate(StorageHelper.java:362)
at com.microsoft.aad.adal.StorageHelper.loadSecretKeyForEncryption(StorageHelper.java:320)
at com.microsoft.aad.adal.StorageHelper.encrypt(StorageHelper.java:178)
at com.microsoft.aad.adal.DefaultTokenCacheStore.encrypt(DefaultTokenCacheStore.java:122)
at com.microsoft.aad.adal.DefaultTokenCacheStore.setItem(DefaultTokenCacheStore.java:190)
at com.microsoft.aad.adal.TokenCacheAccessor.setItemToCacheForUser(TokenCacheAccessor.java:227)
at com.microsoft.aad.adal.TokenCacheAccessor.updateTokenCache(TokenCacheAccessor.java:165)
at com.microsoft.aad.adal.AcquireTokenInteractiveRequest.acquireTokenWithAuthCode(AcquireTokenInteractiveRequest.java:121)
at com.microsoft.aad.adal.AcquireTokenRequest$4.run(AcquireTokenRequest.java:651)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:761)
Caused by: java.security.UnrecoverableKeyException: Failed to obtain X.509 form of public key
at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStorePublicKeyFromKeystore(AndroidKeyStoreProvider.java:230)
at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStoreKeyPairFromKeystore(AndroidKeyStoreProvider.java:259)
at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.loadKeystoreKeyPair(AndroidKeyStoreKeyPairGeneratorSpi.java:509)
... 15 more
Caused by: android.security.KeyStoreException: -22
at android.security.KeyStore.getKeyStoreException(KeyStore.java:666)
at android.security.keystore.AndroidKeyStoreProvider.loadAndroidKeyStorePublicKeyFromKeystore(AndroidKeyStoreProvider.java:231)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
java.security.ProviderException - Failed to load generated key ...
The BasicAndroidKeyStore sample project crashes only on Android P. While trying to generate a key pair.(see attached screenshots) Source code:
Read more >java - AndroidKeyStore KeyPairGenerator Crashes On Small ...
ProviderException : Failed to load generated key pair from keystore at android.security.keystore.AndroidKeyStoreKeyPairGeneratorSpi.
Read more >Crash when trying to load key from keystore (#1696) - briar
UnrecoverableKeyException : Failed to obtain information about key at android.security.keystore.AndroidKeyStoreProvider.
Read more >Key pair not generated, alias <infa_dflt> already exists” when ...
This issue occurs when there is a keystore file already present and you want to modify the keystore file. May be to include...
Read more >KeyGenParameterSpec - Android Developers
The generated key pair or key will be returned by the generator and also stored in the ... getInstance("AndroidKeyStore"); keyStore.load(null); PrivateKey ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@weijjia , the link you provide doesn’t actually contain the above exception and what is happening there
We updated MSAL to 2.2.1 Version, but we got the same error.
[https://github.com/AzureAD/microsoft-authentication-library-for-android/issues/1489]