Registry / security / react-native-encrypted-storage

react-native-encrypted-storage

JSON →
library4.0.3jsnpmunverified

A React Native wrapper around Android's EncryptedSharedPreferences and iOS Keychain to provide a secure alternative to Async Storage. Current version is 4.0.3, released Nov 2021. It supports Android API 21+ and iOS 2.0+. The package includes TypeScript definitions and exposes four async methods: setItem, getItem, removeItem, and clear. Unlike Async Storage, it encrypts data at rest. Requires manual linking for React Native < 0.60; auto-linking for 0.60+. No external dependencies beyond React Native.

npm install react-native-encrypted-storage
INSTALL
IMPORT
SIG · REACT-NATIVE-ENCRY
R
react-native-encrypted-storage
securityjavascriptv4.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import EncryptedStorage from 'react-native-encrypted-storage';
const EncryptedStorage = require('react-native-encrypted-storage').default;
Default export is the main API object. CommonJS users should use require('react-native-encrypted-storage').default or a transpiler.
EncryptedStorage type
import EncryptedStorage from 'react-native-encrypted-storage';
import { EncryptedStorage } from 'react-native-encrypted-storage';
There is no named export. Use default import. TypeScript types are included.
useEncryptedStorage
Not implemented
import { useEncryptedStorage } from 'react-native-encrypted-storage';
This package does not include a React hook. If you attempt named imports, you'll get undefined.

Stores a JSON object encrypted, retrieves it, and shows error handling with native error codes.

import EncryptedStorage from 'react-native-encrypted-storage'; async function storeAndRetrieve() { try { await EncryptedStorage.setItem('secret', JSON.stringify({ token: process.env.API_KEY ?? 'demo' })); const value = await EncryptedStorage.getItem('secret'); console.log(value); // '{"token":"..."}' } catch (error) { console.error(error.code, error.message); } } async function clearAll() { try { await EncryptedStorage.clear(); } catch (error) { console.error(error); } }
Debug
Known issues
breakingVersion 2.x to 3.x removed deprecated methods and changed native storage keys. Data stored with v2 will not be accessible after upgrading to v3.
fix
Migrate data using a migration script before upgrading to v3.
affects: >=2.0.0 <3.0.0
gotchaiOS Keychain data persists after app uninstall. This is expected behavior but can be a security concern if users reinstall the app.
fix
Clear Keychain on first launch using the Objective-C snippet provided in the README.
affects: >=1.0.0
gotchaOn Android, EncryptedSharedPreferences may not use the default master key on some devices, causing potential crashes or data loss.
fix
Ensure Android target API 21+ and test on multiple devices. Consider using a separate encryption library if issues arise.
affects: >=1.0.0
deprecatedMethod `getAllKeys` was removed in v3.0. Use iterative storage keys pattern instead.
fix
Manually track stored keys in your app, e.g., store a list of keys in a separate key.
affects: >=3.0.0
gotchaThe module does not support synchronous methods. All operations are async and must be awaited.
fix
Always use await or .then() when calling methods.
affects: >=1.0.0
Errors
Common errors & fixes
Invariant Violation: Native module cannot be null
react-native link not performed for React Native <0.60, or native module not properly linked.
fix
Run `react-native link react-native-encrypted-storage` for RN <0.60, or check pod install for iOS (npx pod-install).
undefined is not an object (evaluating 'EncryptedStorage.setItem')
Using wrong import (e.g., named import) and getting undefined.
fix
Use default import: `import EncryptedStorage from 'react-native-encrypted-storage';`
Attempted to call an async function in a non-async context
Calling `setItem` or `getItem` without awaiting in a synchronous function.
fix
Wrap the call in an async function or use `.then()`.
Upgrade
Version history
4.0.3latest on npm
Audit
Dependencies
reactrequiredPeer dependency required for React Native functionality
react-nativerequiredPeer dependency; provides native modules access
Agent activity
24 hits · last 30 days
node
24
Resources
react-native-encrypted-storage — npm install react-native-encrypted-storage · libregistry