question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Crash with exception - Failed to load generated key pair from keystore

See original GitHub issue

We 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
caltsengcommented, Feb 1, 2018

@weijjia , the link you provide doesn’t actually contain the above exception and what is happening there

0reactions
saeidz70commented, Oct 9, 2021

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]

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found