Secure storage in React Native is used to safely store sensitive information such as authentication tokens, passwords, API keys, or user secrets. Unlike AsyncStorage, secure storage encrypts data and stores it in platform-specific protected locations.
react-native-keychainReact Native does not provide secure storage out of the box. Libraries like react-native-keychain abstract native secure APIs and expose simple JavaScript methods to store, retrieve, and delete secrets.
// Import secure keychain library
import * as Keychain from 'react-native-keychain';
// Save credentials securely
await Keychain.setGenericPassword('username', 'securePassword');
// Retrieve stored credentials
const credentials = await Keychain.getGenericPassword();
if (credentials) {
console.log(credentials.username, credentials.password);
}
The username and password are encrypted and stored in the device’s secure storage. When retrieved, the decrypted values are returned only to your app. If the user clears app data or uninstalls the app, the stored credentials are removed.
Simulate the "Keychain" process below. Notice how the data stored in the "System Vault" is encrypted (unreadable), but your app retrieves the original value.
react-native-keychain in a new project