# Secure Storage & Secrets

> Store tokens and sensitive data in the Keychain or Keystore, keep secrets out of the app bundle, and protect data at rest. Free notes, key concepts, resources...

Canonical: https://www.internhack.in/roadmaps/tracks/mobile/secure-storage
Last updated: 2026-11-28

Store tokens and sensitive data in the Keychain or Keystore, keep secrets out of the app bundle, and protect data at rest.

Intermediate · about 4 hours · difficulty 3/5

Learn first: [Local Storage: Key-value, SQLite & Files](https://www.internhack.in/roadmaps/tracks/mobile/local-storage), [Authentication & Session Handling](https://www.internhack.in/roadmaps/tracks/mobile/authentication)

Assume your app binary will be downloaded, unzipped and inspected, and that some devices are rooted or jailbroken. Anything shipped inside the app is effectively public.

### Where sensitive data goes

- **Tokens, passwords and keys:** the platform secure store. **Keychain** on iOS and **Keystore**-backed encryption on Android. Wrappers: `expo-secure-store`, `react-native-keychain`, `flutter_secure_storage`, Android's `EncryptedSharedPreferences` successors or DataStore with Tink.
- **Non-sensitive preferences:** AsyncStorage, SharedPreferences, UserDefaults. These are plain files.
- **Databases with personal data:** consider SQLCipher or encrypted Realm, and whether you need to store that data at all.

```
import * as SecureStore from "expo-secure-store";
await SecureStore.setItemAsync("refreshToken", token);
```

### Secrets do not belong in the app

API keys for paid services, database credentials and signing keys must stay on your server. The app should call **your backend**, which holds the secret. Public client keys (Firebase config, Maps keys) are fine to ship but restrict them by package name, bundle id and API scope.

### Other data-at-rest risks

- Logs that print tokens or personal data (strip them in release builds).
- Screenshots in the app switcher showing sensitive screens (blur or secure-flag them).
- Clipboard use for passwords and codes.
- Backups: exclude secrets from cloud backups where appropriate.

### Biometrics

Use biometrics to unlock a key held in the secure store (access control flags), not as a simple yes/no check in JavaScript that could be bypassed.

**Good enough to move on:** your auth tokens live only in secure storage, no private secrets appear in the bundle, and sensitive screens are hidden in the app switcher.

## Key concepts

- **Keychain and Keystore**
- **expo-secure-store and equivalents**
- **Why app bundles cannot hold secrets**
- **Restricting public API keys**
- **Encrypted databases**
- **Log and screenshot hygiene**
- **Biometric-bound keys**

## Mini project

Refactor an app that stores tokens in plain storage to use secure storage, move a third-party API key behind a small backend proxy, and blur the app in the task switcher.

## Check yourself

A teammate wants to put a payment provider secret key in an environment variable bundled with the app. What do you tell them?

## Free resources

- [Expo: SecureStore](https://docs.expo.dev/versions/latest/sdk/securestore/) (Expo)
- [React Native: Security](https://reactnative.dev/docs/security) (React Native)
- [Android: Keystore system](https://developer.android.com/privacy-and-security/keystore) (Android Developers)

Previous: [Internationalization & Localization](https://www.internhack.in/roadmaps/tracks/mobile/localization) · Next: [Mobile App Security with OWASP MASVS](https://www.internhack.in/roadmaps/tracks/mobile/app-security-masvs)

## More in Accessibility, Localization & Security

- [Mobile Accessibility](https://www.internhack.in/roadmaps/tracks/mobile/accessibility)
- [Internationalization & Localization](https://www.internhack.in/roadmaps/tracks/mobile/localization)
- [Secure Storage & Secrets](https://www.internhack.in/roadmaps/tracks/mobile/secure-storage)
- [Mobile App Security with OWASP MASVS](https://www.internhack.in/roadmaps/tracks/mobile/app-security-masvs)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Mobile App Developer Roadmap](https://www.internhack.in/roadmaps/tracks/mobile)
