I am getting the below exception. But the KeyStoreException is not caught. And I can read ProviderException. Can I first understand, why two exceptions are thrown and also, why I cannot catch KeyStoreException.
In my code -
try{
generateKeyApi()
}catch(e: Exception){
when(e){
is KeyStoreException -> Log.i("Key store exception")
else -> Log.i("Its not a keystore exception")
}
}
05-26 12:33:20.104 3153 3153 E : Exception occurred in the application's task.
05-26 12:33:20.104 3153 3153 E : java.security.ProviderException: Keystore
operation failed
05-26 12:33:20.104 3153 3153 E : at
.engineGenerateKey(AndroidKeyStoreKeyGeneratorSpi.java:322)
05-26 12:33:20.104 3153 3153 E : at javax.crypto.KeyGenerator.generateKey
(KeyGenerator.java:604)
05-26 12:33:20.104 3153 3153 E : .....
05-26 12:33:20.104 3153 3153 E : at java.util.concurrent.FutureTask.run
(FutureTask.java:266)
05-26 12:33:20.104 3153 3153 E : at android.os.Handler.handleCallback
(Handler.java:789)
05-26 12:33:20.104 3153 3153 E : at android.os.Handler.dispatchMessage
(Handler.java:98)
05-26 12:33:20.104 3153 3153 E : at android.os.Looper.loop(Looper.java:164)
05-26 12:33:20.104 3153 3153 E : at android.os.HandlerThread.run
(HandlerThread.java:65)
05-26 12:33:20.104 3153 3153 E : Caused by: android.security.KeyStoreException:
User authentication required
05-26 12:33:20.104 3153 3153 E : at
android.security.KeyStore.getKeyStoreException(KeyStore.java:1112)
05-26 12:33:20.104 3153 3153 E : at
android.security.keystore.AndroidKeyStoreKeyGeneratorSpi
.engineGenerateKey(AndroidKeyStoreKeyGeneratorSpi.java:323)
05-26 12:33:20.104 3153 3153 E : ... 32 more