
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
rn-secure-storage
Advanced tools
Secure Storage for React Native (Android & iOS) - Keychain & Keystore
Secure Storage for React Native (Android & iOS) - Keychain & Keystore
Please read my disclaimer about maintaining this library here
For Android I need your reviews
With NPM
npm install --save rn-secure-storage
With YARN
yarn add rn-secure-storage
clear
for comprehensive data clearance.getAllKeys
for retrieving all stored keys.multiSet
for setting multiple values simultaneously.multiGet
feature for fetching multiple values at once.multiRemove
added for bulk deletion of items.getSupportedBiometryType
introduced for iOS (supports biometric authentication types).To set the item, you need to pass the key and value as parameters. You can also pass the options as a third parameter. If the key exists,
the value will be updated, otherwise, it will be created. You can use the exists
method to check if the key exists. You can also pass
the accessible
option to set the accessibility of the keychain item (only for IOS).
import RNSecureStorage, {ACCESSIBLE} from 'rn-secure-storage';
RNSecureStorage.setItem("key", "value", {accessible: ACCESSIBLE.WHEN_UNLOCKED}).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
To get the item, you need to pass the key as a parameter. If the key exists, the value will be returned, otherwise, it will return an error.
RNSecureStorage.getItem("key").then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
To remove the item, you need to pass the key as a parameter. If the key exists, the value will be removed, otherwise, it will return an error.
RNSecureStorage.removeItem("key").then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
To check if the item exists, you need to pass the key as a parameter. If the key exists it will return true
, otherwise, it will
return false
. Mostly you don't need to use this method because getItem
will return an error if the key doesn't exist. But for
performance you can just check if the key exists before calling getItem
.
RNSecureStorage.exist("key").then((res) => {
console.log(res ? "exists" : "does not exist");
}).catch((err) => {
console.log(err);
});
To get all keys, you need to call getAllKeys
method. It will return an array of keys.
RNSecureStorage.getAllKeys().then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
To clear all data, you need to call clear
method. It will return true
if the operation is successful. Otherwise, it will return
remaining keys.
RNSecureStorage.clear().then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
Multi set is a new feature that allows you to set multiple values simultaneously. You need to pass an object as the first parameter
import RNSecureStorage, {ACCESSIBLE} from 'rn-secure-storage';
const items = {"key_1": "multi key 1", "key_2": "multi key 2"};
RNSecureStorage.multiSet(items, {accessible: ACCESSIBLE.WHEN_UNLOCKED}).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
With multi get you can fetch multiple values at once. You need to pass an array of keys as the first parameter.
RNSecureStorage.multiGet(["key_1", "key_2"]).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
With multi remove you can delete multiple values at once. You need to pass an array of keys as the first parameter. If your keys are removed/not found, it will return an array of keys that are not removed/found.
RNSecureStorage.multiRemove(["key_1", "key_2"]).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
Key | Platform | Description | Default |
---|---|---|---|
accessible | iOS only | This indicates when a keychain item is accessible, see possible values in Keychain.ACCESSIBLE . | Keychain.ACCESSIBLE.WHEN_UNLOCKED |
Keychain.ACCESSIBLE
enumKey | Description |
---|---|
WHEN_UNLOCKED | The data in the keychain item can be accessed only while the device is unlocked by the user. |
AFTER_FIRST_UNLOCK | The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user. |
ALWAYS | The data in the keychain item can always be accessed regardless of whether the device is locked. |
WHEN_PASSCODE_SET_THIS_DEVICE_ONLY | The data in the keychain can only be accessed when the device is unlocked. Only available if a passcode is set on the device. Items with this attribute never migrate to a new device. |
WHEN_UNLOCKED_THIS_DEVICE_ONLY | The data in the keychain item can be accessed only while the device is unlocked by the user. Items with this attribute do not migrate to a new device. |
AFTER_FIRST_UNLOCK_THIS_DEVICE_ONLY | The data in the keychain item cannot be accessed after a restart until the device has been unlocked once by the user. Items with this attribute never migrate to a new device. |
ALWAYS_THIS_DEVICE_ONLY | The data in the keychain item can always be accessed regardless of whether the device is locked. Items with this attribute never migrate to a new device. |
This project is licensed under the MIT License - see the LICENSE.md file for details
I have rewritten the Android module with enhanced security features. I need your reviews. Please test the new version and let me know your thoughts. I will be happy to hear your suggestions and comments. I'm planning to release the new version to handle biometric authentication on Android.
As an open-source enthusiast and developer, I originally created this library for professional use. However, with recent changes in my career, my focus has shifted away from React Native, limiting my involvement to personal projects. Consequently, my time to address issues and review pull requests for this library has become restricted. I remain committed to maintaining and improving this library, but my response times might be longer. I greatly appreciate your patience and understanding.
The beauty of open-source is in collaboration. If you find this library useful and would like to contribute, whether through code, addressing issues, or even buying a coffee to show support, it would be immensely appreciated. Together, we can ensure the continued development and enhancement of this library.
FAQs
Secure Storage for React Native (Android & iOS) - Keychain & Keystore
The npm package rn-secure-storage receives a total of 2,791 weekly downloads. As such, rn-secure-storage popularity was classified as popular.
We found that rn-secure-storage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.