How aparajita/capacitor-secure-storage works
This is a Capacitor plugin for storing JSON-compatible key/value data securely on iOS and Android, with an explicitly debug-only web implementation. The workflow is: callers use the registered plugin API; a shared layer handles prefixes, serialization, sync/access options, and errors; platform adapters perform storage operations. iOS uses the system keychain with optional iCloud synchronization, while Android encrypts values with AES-GCM using Android KeyStore keys and stores them in app-specific SharedPreferences. The README documents platform behavior; unsampled implementation details and links are omitted where not evidenced.
Main entry points: index.ts Platform registration · native.ts Native adapter · SecureStorage.java Android plugin · web.ts Web adapter
Components 14
Plugin API
- Public API
src/definitions.ts - Platform registration
src/index.ts
Shared runtime
- Storage operations
src/base.ts - Native adapter
src/native.ts - Web adapter
src/web.ts - Browser storage
iOS storage
- Keychain plugin
ios/Sources/SecureStoragePlugin/Plugin.swift - Keychain errors
ios/Sources/SecureStoragePlugin/KeychainError.swift - System keychain
Android storage
- Android plugin
android/src/main/java/com/aparajita/capacitor/securestorage/SecureStorage.java - Storage errors
android/src/main/java/com/aparajita/capacitor/securestorage/KeyStoreException.java - Android KeyStore
- SharedPreferences
Other components
- Application
Connections 15
- Application → Platform registration: uses plugin
src/index.ts - Platform registration → Native adapter: loads native
src/index.ts - Platform registration → Web adapter: loads web
src/index.ts - Platform registration → Public API: exposes types
src/index.ts - Native adapter → Storage operations: extends operations
src/native.ts - Web adapter → Storage operations: extends operations
src/web.ts - Storage operations → Public API: implements contract
src/base.ts - Web adapter → Browser storage: stores values
README.md - Native adapter → Keychain plugin: dispatches calls
- Native adapter → Android plugin: dispatches calls
- Keychain plugin → System keychain: reads and writes
ios/Sources/SecureStoragePlugin/Plugin.swift - Keychain plugin → Keychain errors: rejects errors
ios/Sources/SecureStoragePlugin/Plugin.swift - Android plugin → Android KeyStore: encrypts with keys
README.md - Android plugin → SharedPreferences: stores ciphertext
README.md - Android plugin → Storage errors: reports failures
android/src/main/java/com/aparajita/capacitor/securestorage/SecureStorage.java