react-native-secure-key-store icon indicating copy to clipboard operation
react-native-secure-key-store copied to clipboard

Need RSA private or public key error

Open mahesh-vidhate opened this issue 5 years ago • 5 comments

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

mahesh-vidhate avatar Oct 30 '18 10:10 mahesh-vidhate

@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?

benjiekibblewhite avatar Feb 08 '19 20:02 benjiekibblewhite

@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"> . .

mahesh-vidhate avatar Feb 09 '19 16:02 mahesh-vidhate

Thanks @mahesh-vidhate , works like a charm 👍

MaximeConan avatar Feb 04 '20 16:02 MaximeConan

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

JacopoKenzo avatar Apr 16 '20 02:04 JacopoKenzo

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

kdreibel avatar Jun 18 '21 21:06 kdreibel