oblador / react-native-keychain

:key: Keychain Access for React Native
MIT License
3.22k stars 518 forks source link

Could not get key from Keystore #179

Open anshul-kai opened 5 years ago

anshul-kai commented 5 years ago

I'm consistently receiving errors on my Android 8.0 where I'm unable to perform any Keystore actions. I'm not too familiar with the Keychain and wondering if it doesn't work consistently in certain use cases?

danielgindi commented 5 years ago

Yes, me too.

danielgindi commented 5 years ago

The internal cause is UnrecoverableKeyException: Failed to obtain information about key

anshul-kai commented 5 years ago

Thanks for sharing @danielgindi. I added some try/catches to my production code and am noticing a few CryptoFailedException as well. It would be a good idea to add to documentation that this won't work on some devices. Works on 95%+ devices from what I'm noticing.

Thoughts @oblador?

danielgindi commented 5 years ago

I think it's a timing issue. The keychain may be locked/unlocked depending on some user action, how long since they unlocked the device or something like that.

dmathewwws commented 5 years ago

I'm noticing this on the Nexus_5X (API 27) emulator I am using.

Get the exception Could not get key from Keystore

hellogerard commented 5 years ago

I've been experiencing The provided service/key could not be found in the Keystore, which from my reading of the code, shouldn't be possible, because it would mean the value is there, but its encryption key is not.

dhanashree27 commented 5 years ago

@hellogerard Did you find any solution for this ? I am facing same issue

hellogerard commented 5 years ago

@dhanashree27 I found that these users uninstalled and reinstalled the app for some reason. Uninstalling the app will wipe SharedPreferences and Keystore entries for the app. But if you have Google Auto Backup on (which is the default), then when you reinstall the app, your SharedPreferences will get restored, restoring your encrypted values. But Auto Backup does not backup your Keystore, so then you will have the values but not the keys, resulting in this error.

OleksandrKucherenko commented 4 years ago

But Auto Backup does not backup your Keystore, so then you will have the values but not the keys, resulting in this error.

Any suggestions how to solve that?