Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aparajita/capacitor-secure-storage
Secure, flexible storage for Capacitor apps using iOS Keychain and Android Keystore.
https://github.com/aparajita/capacitor-secure-storage
capacitor capacitor-android capacitor-ios capacitor-plugin capacitor-plugins keychain storage
Last synced: 24 days ago
JSON representation
Secure, flexible storage for Capacitor apps using iOS Keychain and Android Keystore.
- Host: GitHub
- URL: https://github.com/aparajita/capacitor-secure-storage
- Owner: aparajita
- License: mit
- Created: 2020-11-10T05:51:17.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-17T22:14:17.000Z (5 months ago)
- Last Synced: 2024-11-14T05:35:18.874Z (29 days ago)
- Topics: capacitor, capacitor-android, capacitor-ios, capacitor-plugin, capacitor-plugins, keychain, storage
- Language: TypeScript
- Homepage:
- Size: 433 KB
- Stars: 108
- Watchers: 8
- Forks: 15
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-capacitorjs - @aparajita/capacitor-secure-storage - Secure, flexible storage for Capacitor apps using iOS Keychain and Android Keystore. (Plugins / Community Plugins)
- awesome-capacitor - Secure Storage - Secure, flexible storage for Capacitor apps using iOS Keychain and Android Keystore. Supports Keychain sync across devices on iOS. ([Aparajita plugins](https://github.com/aparajita?tab=repositories&q=capacitor))
README
# capacitor-secure-storage
This plugin for [Capacitor 6+](https://capacitorjs.com) provides secure key/value storage on iOS and Android. It was originally designed to be a companion to [@aparajita/capacitor-biometric-auth](https://github.com/aparajita/capacitor-biometric-auth/#readme) in order to securely store login credentials, but can be used to store any JSON data types.
## BREAKING CHANGES: Upgrading from 5.x
The minimum Android API level was increased from 22 to 23 (Android 6).
## BREAKING CHANGES: Upgrading from 2.x
To be consistent with JavaScript’s `Storage` and `@capacitor/preferences`, the plugin now returns `null` instead of throwing an exception when getting a non-existent item.
Also, the plugin no longer encrypts data on the web, since this plugin is designed for native storage, and including blowfish was unnecessary bloat.
## Installation
```sh
pnpm add @aparajita/capacitor-secure-storage # npm install, yarn add
```Not using [pnpm](https://pnpm.js.org/)? You owe it to yourself to give it a try. It’s faster, better with monorepos, and uses _way, way_ less disk space than the alternatives.
## Usage
The API is thoroughly documented [here](src/definitions.ts). For a complete example of how to use this plugin in practice, see the [demo app](https://github.com/aparajita/capacitor-secure-storage-demo).
### iOS
On iOS, data is stored in the encrypted system keychain and is specific to your app. Please note that currently iOS will **not** delete an app’s keychain data when the app is deleted. But since only an app with the same app id — which is guaranteed by Apple to be unique across all apps — can access that data, this is not a security issue.
#### iCloud Keychain sync
You may synchronize data with iCloud Keychain. Synchronization can be controlled globally and per operation. This allows you to share secure data (such as login credentials) for the same app across multiple devices.
> 👉 The user must enable iCloud Keychain on a device in order for data to sync.
To turn sync on or off globally, call `setSynchronize()`. You can override the global setting per operation by passing a boolean in the `sync` option.
Note that iOS considers the local keychain and iCloud keychain as two separate keychains. Which keychain is affected by an operation depends on the global and per operation sync setting. This means, for example, that a value can be stored and retrieved with the same key in both keychains.
> 👉 When the resolved sync setting is true, calls to `keys()` return the keys for **both** the iCloud and local keychains. Thus there may be duplicates.
### Android
On Android, data is encrypted using AES in GCM mode with a secret key generated by the Android KeyStore, then stored in SharedPreferences, which is specific to your app. If the app is deleted, its data is deleted as well.
### Web
On the web, data is stored **unencrypted** in `localStorage`, so that you can see the data you are storing. This is for debugging purposes only; you should not use this plugin on the web in production.