react-native-keychain and react-native-sensitive-info are both libraries designed to store sensitive data securely on mobile devices using native security hardware. react-native-keychain focuses on storing credentials (username and password pairs) or generic secrets directly in the iOS Keychain and Android Keystore system. react-native-sensitive-info provides a key-value storage interface that also leverages native secure storage but abstracts it as a simple dictionary. Both aim to prevent data exposure if the device is compromised, but they differ in API design, security defaults, and maintenance status.
Both react-native-keychain and react-native-sensitive-info solve the same core problem โ keeping secrets safe on a user's device. They both tap into native security hardware like the iOS Keychain and Android Keystore. However, they approach the task differently, and one is generally safer for critical data like login tokens. Let's look at how they handle security, API design, and real-world usage.
react-native-keychain treats data as credentials.
// react-native-keychain: Stores as credentials
import * as Keychain from 'react-native-keychain';
await Keychain.setGenericPassword('user123', 'token_xyz', {
service: 'com.example.app',
accessControl: Keychain.ACCESS_CONTROL.BIOMETRY_ANY,
});
react-native-sensitive-info treats data as key-value pairs.
// react-native-sensitive-info: Stores as key-value
import RNSensitiveInfo from 'react-native-sensitive-info';
await RNSensitiveInfo.setItem('auth_token', 'token_xyz', {
sharedPreferencesName: 'secure_prefs',
keychainService: 'com.example.app',
});
react-native-keychain has a strict structure.
username and password fields.// react-native-keychain: Structured retrieval
const credentials = await Keychain.getGenericPassword({
service: 'com.example.app',
});
if (credentials) {
console.log(credentials.username); // 'user123'
console.log(credentials.password); // 'token_xyz'
}
react-native-sensitive-info is more flexible.
// react-native-sensitive-info: Flexible retrieval
const token = await RNSensitiveInfo.getItem('auth_token');
const settings = await RNSensitiveInfo.getAllItems();
console.log(token); // 'token_xyz'
console.log(settings); // { auth_token: 'token_xyz', ... }
react-native-keychain integrates biometrics directly.
// react-native-keychain: Biometric lock
await Keychain.setGenericPassword('user', 'pass', {
accessControl: Keychain.ACCESS_CONTROL.BIOMETRY_ANY,
accessible: Keychain.ACCESSIBLE.WHEN_PASSCODE_SET_THIS_DEVICE_ONLY,
});
// Retrieval triggers biometric prompt
const creds = await Keychain.getGenericPassword({
accessControl: Keychain.ACCESS_CONTROL.BIOMETRY_ANY,
});
react-native-sensitive-info supports biometrics but requires setup.
// react-native-sensitive-info: Biometric options
await RNSensitiveInfo.setItem('secret', 'value', {
keychainService: 'com.example.app',
// Requires native config to enforce biometrics strictly
});
const value = await RNSensitiveInfo.getItem('secret', {
keychainService: 'com.example.app',
});
react-native-keychain uses the Android Keystore system.
// react-native-keychain: Android Keystore enforced
// No extra code needed โ library handles Keystore integration
await Keychain.setGenericPassword('user', 'pass', {
storage: Keychain.STORAGE_TYPE.AES, // Uses hardware-backed AES
});
react-native-sensitive-info uses EncryptedSharedPreferences.
// react-native-sensitive-info: EncryptedSharedPreferences
// Ensure library version is up-to-date to avoid plaintext storage
await RNSensitiveInfo.setItem('key', 'value', {
sharedPreferencesName: 'encrypted_prefs',
});
react-native-keychain is widely adopted for auth.
// react-native-keychain: Community standard
// Widely used in boilerplates like Ignite or React Native Template
import * as Keychain from 'react-native-keychain';
react-native-sensitive-info has had maintenance gaps.
// react-native-sensitive-info: Check maintenance
// Verify active maintenance before adding to critical paths
import RNSensitiveInfo from 'react-native-sensitive-info';
While they differ in focus, both libraries share core capabilities for secure storage.
// Both persist data across app restarts
// Keychain
await Keychain.setGenericPassword('u', 'p');
// SensitiveInfo
await RNSensitiveInfo.setItem('k', 'v');
// Keychain: Reset credentials
await Keychain.resetGenericPassword();
// SensitiveInfo: Delete specific key
await RNSensitiveInfo.deleteItem('auth_token');
// Keychain: Service option
await Keychain.setGenericPassword('u', 'p', { service: 'my.app' });
// SensitiveInfo: KeychainService option
await RNSensitiveInfo.setItem('k', 'v', { keychainService: 'my.app' });
| Feature | Shared by Both |
|---|---|
| iOS Storage | ๐ Keychain |
| Android Storage | ๐ค Keystore / EncryptedPrefs |
| Persistence | ๐พ Survives app restarts |
| Logout Support | ๐๏ธ Clear data methods |
| Namespacing | ๐ท๏ธ Service names supported |
| Feature | react-native-keychain | react-native-sensitive-info |
|---|---|---|
| Data Model | ๐ Credentials (User/Pass) | ๐ Key-Value Dictionary |
| Android Security | ๐ก๏ธ Hardware Keystore (Strict) | ๐ EncryptedSharedPreferences |
| Biometrics | ๐ Built-in API options | โ๏ธ Configurable via options |
| Maintenance | โ Active & Standard | โ ๏ธ Check current status |
| Best For | ๐ Auth Tokens & Logins | ๐ General Secure Config |
react-native-keychain is the specialist tool ๐ โ built specifically for authentication flows. It enforces better security defaults on Android and matches the mental model of logging in (username + password). Use this for anything related to user sessions.
react-native-sensitive-info is the generalist tool ๐๏ธ โ built for storing various secure settings. It is flexible but requires more diligence to ensure Android security is configured correctly. Use this for non-critical secrets or if you need a simple dictionary interface.
Final Thought: Security is not just about encryption โ it is about maintenance and defaults. For most professional apps, react-native-keychain provides a safer baseline with less room for configuration errors.
Choose react-native-keychain if you are storing authentication tokens, user credentials, or high-security secrets. It offers stronger guarantees on Android by leveraging the Keystore system more rigorously and includes built-in support for biometric authentication constraints. It is the industry standard for login sessions and should be your default choice for auth flows.
Choose react-native-sensitive-info if you need simple key-value storage for non-critical sensitive config and prefer a dictionary-style API. However, verify the current maintenance status before adopting, as there have been historical concerns regarding Android security defaults in older versions. It is suitable for less critical data where credential-style storage is not required.
react-native-keychainThis library provides access to the Keychain (iOS) and Keystore (Android) for securely storing credentials like passwords, tokens, or other sensitive information in React Native apps.
yarn add react-native-keychainpod install in ios/ directory to install iOS dependencies.NSFaceIDUsageDescription entry in your Info.plist.Please refer to the documentation website on https://oblador.github.io/react-native-keychain
Check the GitHub Releases page.
Joel Arvidsson Author |
Dorian Mazur Maintainer |
Vojtech Novak Maintainer |
Pelle Stenild Coltau Maintainer |
Oleksandr Kucherenko Contributor |
This library is used by several projects, including:
MIT ยฉ Joel Arvidsson 2016-2020