pradeep1991singh / react-native-secure-key-store

React Native Library for securely storing keys to iOS KeyChain and Android KeyStore.
ISC License
238 stars 69 forks source link

Need RSA private or public key error #33

Open mahesh-vidhate opened 5 years ago

mahesh-vidhate commented 5 years ago

I am getting this error on Samsung Galaxy S8 Android device, for other Android devices, it works. This error occurs while either setting or getting the key stored in Keystore. following is my code -

code to set key

exports.SET_KEY = (randomKey) => { RNSecureKeyStore.set(KEY_STORE_KEYNAME, randomKey) .then((res) => { console.log(res); }, (err) => { console.log("SET_KEY",err); }); }

code to get key

exports.GET_KEY = (success, fail) => { RNSecureKeyStore.get(KEY_STORE_KEYNAME) .then((res) => { console.log(res); success(res) }, (err) => { console.log('GET_KEY', err); fail(KEY_NOT_FOUND) }); }

I am getting error as,

Error: {"code":9,"api-level":26,"message":Need RSA private or public key} at createErrorFromErrorData (NativeModules.js:146) at NativeModules.js:95 at MessageQueue.invokeCallback (MessageQueue.js:397) at MessageQueue.js:127 at MessageQueue.guard (MessageQueue.js:297) at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126) at debuggerWorker.js:72

benjiekibblewhite commented 5 years ago

@mahesh-vidhate I am also getting this error on a Galaxy s9, but not every time. I check for an item in the store on initial app load, and that's the one where I am getting the error. Did you ever find a solution?

mahesh-vidhate commented 5 years ago

@ostaron Apologise for the delay. To solve this issue you need clear the app data manually from the setting. You may find that from setting -> installed apps -> youAppName. This is usually happening because after uninstalling the app from the device, OS still keeps some data of it. So when you install the same app again, OS failed to update your keystore with new keys you are trying to store. To solve this issue I put the following code in the manifest to remove all data of app on uninstallation. <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="..."> <application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme" android:allowBackup="false" tools:replace="android:allowBackup"> . .

MaximeConan commented 4 years ago

Thanks @mahesh-vidhate , works like a charm 👍

JacopoKenzo commented 4 years ago

@mahesh-vidhate you just saved my life! Thanks man ❤️

kdreibel commented 3 years ago

You can also uninstall the app and run CCleaner. It accomplishes the same thing.