---
description: Capacitor plugin to securely store and retrieve sensitive data like passwords and tokens using native secure storage mechanisms.
title: Capacitor Secure Preferences Plugin - Capawesome
image: https://capawesome.io/docs/assets/images/social/plugins/secure-preferences.png
---

[ Skip to content](#capawesome-teamcapacitor-secure-preferences) 

[ 🎉 Introducing **Capawesome Platform** — one platform for Live Updates, Native Builds, App Store Publishing, and Insider SDKs.](https://capawesome.io) 

* [  Formbricks ](/docs/plugins/formbricks/)
* [  Geocoder ](/docs/plugins/geocoder/)
* [  Google Sign-In ](/docs/plugins/google-sign-in/)
* [  libSQL ](/docs/plugins/libsql/)
* [  Live Update ](/docs/plugins/live-update/)
* [  Managed Configurations ](/docs/plugins/managed-configurations/)
* [  Media Session ](/docs/plugins/media-session/)
* [  ML Kit ](/docs/plugins/mlkit/)
* [  NFC ](/docs/plugins/nfc/)
* [  OAuth ](/docs/plugins/oauth/)
* [  Pedometer ](/docs/plugins/pedometer/)
* [  Photo Editor ](/docs/plugins/photo-editor/)
* [  PostHog ](/docs/plugins/posthog/)
* [  Printer ](/docs/plugins/printer/)
* [  Purchases ](/docs/plugins/purchases/)
* [  RealtimeKit ](/docs/plugins/realtimekit/)
* [  Screen Orientation ](/docs/plugins/screen-orientation/)
* [  Screenshot ](/docs/plugins/screenshot/)
* Secure Preferences [  Secure Preferences ](/docs/plugins/secure-preferences/)
* [  Configuration ](#configuration)
* [  Usage ](#usage)
* [  API ](#api)
* [  Changelog ](#changelog)
* [  Breaking Changes ](#breaking-changes)
* [  License ](#license)
* [  Speech Recognition ](/docs/plugins/speech-recognition/)
* [  Speech Synthesis ](/docs/plugins/speech-synthesis/)
* [  Share Target ](/docs/plugins/share-target/)
* [  Square Mobile Payments ](/docs/plugins/square-mobile-payments/)
* [  SQLite ](/docs/plugins/sqlite/)
* [  Superwall ](/docs/plugins/superwall/)
* [  Torch ](/docs/plugins/torch/)
* [  Wifi ](/docs/plugins/wifi/)
* [  Zip ](/docs/plugins/zip/)
* [  Cloud ](/docs/cloud/)
* [  Live Updates ](/docs/cloud/live-updates/)
* Advanced
* Integrations
* [  Native Builds ](/docs/cloud/native-builds/)
* [  Configuration ](/docs/cloud/native-builds/configuration/)
* [  Environments ](/docs/cloud/native-builds/environments/)
* Guides
* [  Sample Projects ](/docs/cloud/native-builds/sample-projects/)
* [  Troubleshooting ](/docs/cloud/native-builds/troubleshooting/)
* [  Automations ](/docs/cloud/automations/)
* [  Assist ](/docs/cloud/assist/)
* Account
* Organizations
* [  Organization and User Management ](/docs/cloud/organizations/memberships/)
* [  Single Sign-On (SSO) ](/docs/cloud/organizations/sso/)
* [  Teams ](/docs/cloud/organizations/teams/)
* [  Two-Factor Authentication ](/docs/cloud/organizations/two-factor-authentication/)
* [  Integrations ](/docs/cloud/integrations/)
* [  License Keys ](/docs/cloud/license-keys/)
* [  Webhooks ](/docs/cloud/webhooks/)
* [  Pricing ](https://capawesome.io/pricing/)
* [  FAQ ](/docs/cloud/faq/)
* [  Support ](/docs/cloud/support/)
* [  Contributing ](/docs/contributing/)
* [  LLMs ](/docs/llms/)
* [  Insiders ](/docs/insiders/)
* [  License ](https://capawesome.io/legal/eula/)
* [  Support ](/docs/insiders/support/)
* [  FAQ ](/docs/insiders/faq/)
* [  Blog ](/blog/)
* Categories

* [  Configuration ](#configuration)
* [  Usage ](#usage)
* [  API ](#api)
* [  Changelog ](#changelog)
* [  Breaking Changes ](#breaking-changes)
* [  License ](#license)

# @capawesome-team/capacitor-secure-preferences[¶](#capawesome-teamcapacitor-secure-preferences "Permanent link")

Capacitor plugin to securely store key/value pairs such as passwords, tokens or other sensitive information.

[ ![Deliver Live Updates to your Capacitor app with Capawesome Cloud](../../assets/external/cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.69628c3f.png) ](https://cloud.capawesome.io/) 

## Features[¶](#features "Permanent link")

We are proud to offer one of the most complete and feature-rich Capacitor plugins for secure storage. Here are some of the key features:

* 🖥️ **Cross-platform**: Supports Android, iOS and Web.
* 🔒 **Secure**: Store sensitive information such as passwords securely using the [Android Keystore](https://developer.android.com/privacy-and-security/keystore) and [iOS Keychain](https://developer.apple.com/documentation/security/keychain-services).
* 🔍 **Detailed Error Messages**: Get actionable error messages with specific failure reasons and error codes on iOS, making debugging keychain issues straightforward.
* 🤝 **Compatibility**: Compatible with the [Biometrics](https://capawesome.io/docs/plugins/biometrics/) and [SQLite](https://capawesome.io/docs/plugins/sqlite/) plugins.
* 📦 **CocoaPods & SPM**: Supports CocoaPods and Swift Package Manager for iOS.
* 🔁 **Up-to-date**: Always supports the latest Capacitor version.
* ⭐️ **Support**: Priority support from the Capawesome Team.
* ✨ **Handcrafted**: Built from the ground up with care and expertise, not forked or AI-generated.

Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!

## Newsletter[¶](#newsletter "Permanent link")

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).

## Compatibility[¶](#compatibility "Permanent link")

| Plugin Version | Capacitor Version | Status         |
| -------------- | ----------------- | -------------- |
| 0.2.x          | \>=8.x.x          | Active support |

## Guides[¶](#guides "Permanent link")

* [Alternative to the Ionic Secure Storage plugin](https://capawesome.io/blog/alternative-to-ionic-secure-storage-plugin/)
* [Announcing the Capacitor Secure Preferences Plugin](https://capawesome.io/blog/announcing-the-capacitor-secure-preferences-plugin/)
* [Exploring the Capacitor Secure Preferences API](https://capawesome.io/blog/exploring-the-capacitor-secure-preferences-api/)
* [How to Securely Store Credentials with Capacitor](https://capawesome.io/blog/how-to-securely-store-credentials-with-capacitor/)

## Installation[¶](#installation "Permanent link")

This plugin is only available to [Capawesome Insiders](https://capawesome.io/insiders/). First, make sure you have the Capawesome npm registry set up. You can do this by running the following commands:

`[](#%5F%5Fcodelineno-0-1)npm config set @capawesome-team:registry https://npm.registry.capawesome.io
[](#%5F%5Fcodelineno-0-2)npm config set //npm.registry.capawesome.io/:_authToken <YOUR_LICENSE_KEY>
`

**Attention**: Replace `<YOUR_LICENSE_KEY>` with the license key you received from Polar. If you don't have a license key yet, you can get one by becoming a [Capawesome Insider](https://capawesome.io/insiders/).

Next, you can use our **AI-Assisted Setup** to install the plugin. Add the [Capawesome Skills](https://github.com/capawesome-team/skills) to your AI tool using the following command:

`[](#%5F%5Fcodelineno-1-1)npx skills add capawesome-team/skills --skill capacitor-plugins
`

Then use the following prompt:

`` [](#%5F%5Fcodelineno-2-1)Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome-team/capacitor-secure-preferences` plugin in my project.
 ``

If you prefer **Manual Setup**, install the plugin by running the following commands and follow the platform-specific instructions below:

`[](#%5F%5Fcodelineno-3-1)npm install @capawesome-team/capacitor-secure-preferences
[](#%5F%5Fcodelineno-3-2)npx cap sync
`

### Android[¶](#android "Permanent link")

#### Backup rules[¶](#backup-rules "Permanent link")

To prevent the preferences file from being backed up to the cloud, you need to add backup rules to your Android project. You can read more about this in the [Android documentation](https://developer.android.com/identity/data/autobackup#IncludingFiles).

##### Android 11 and lower[¶](#android-11-and-lower "Permanent link")

Add the `android:fullBackupContent` attribute to the `<application>` tag in your `AndroidManifest.xml` file:

`[](#%5F%5Fcodelineno-4-1)<application
[](#%5F%5Fcodelineno-4-2)  android:fullBackupContent="@xml/full_backup_content">
[](#%5F%5Fcodelineno-4-3)</application>
`

Create a new file `res/xml/full_backup_content.xml` with the following content:

`[](#%5F%5Fcodelineno-5-1)<?xml version="1.0" encoding="utf-8"?>
[](#%5F%5Fcodelineno-5-2)<full-backup-content>
[](#%5F%5Fcodelineno-5-3)  <include domain="sharedpref" path="."/>
[](#%5F%5Fcodelineno-5-4)  <exclude domain="sharedpref" path="CAPAWESOME_SECURE_PREFERENCES.xml"/>
[](#%5F%5Fcodelineno-5-5)</full-backup-content>
`

##### Android 12 and higher[¶](#android-12-and-higher "Permanent link")

Add the `android:dataExtractionRules` attribute to the `<application>` tag in your `AndroidManifest.xml` file:

`[](#%5F%5Fcodelineno-6-1)<application
[](#%5F%5Fcodelineno-6-2)  android:dataExtractionRules="@xml/data_extraction_rules">
[](#%5F%5Fcodelineno-6-3)</application>
`

Create a new file `res/xml/data_extraction_rules.xml` with the following content:

`[](#%5F%5Fcodelineno-7-1)<?xml version="1.0" encoding="utf-8"?>
[](#%5F%5Fcodelineno-7-2)<data-extraction-rules>
[](#%5F%5Fcodelineno-7-3) <cloud-backup [disableIfNoEncryptionCapabilities="true|false"]>
[](#%5F%5Fcodelineno-7-4)   <include domain="sharedpref" path="."/>
[](#%5F%5Fcodelineno-7-5)   <exclude domain="sharedpref" path="CAPAWESOME_SECURE_PREFERENCES.xml"/>
[](#%5F%5Fcodelineno-7-6) </cloud-backup>
[](#%5F%5Fcodelineno-7-7)</data-extraction-rules>
`

#### Proguard[¶](#proguard "Permanent link")

If you are using Proguard, you need to add the following rules to your `proguard-rules.pro` file:

`[](#%5F%5Fcodelineno-8-1)-keep class io.capawesome.capacitorjs.plugins.** { *; }
`

## Configuration[¶](#configuration "Permanent link")

No configuration required for this plugin.

## Usage[¶](#usage "Permanent link")

`[](#%5F%5Fcodelineno-9-1)import { SecurePreferences } from '@capawesome-team/capacitor-secure-preferences';
[](#%5F%5Fcodelineno-9-2)
[](#%5F%5Fcodelineno-9-3)const clear = async () => {
[](#%5F%5Fcodelineno-9-4)  await SecurePreferences.clear();
[](#%5F%5Fcodelineno-9-5)};
[](#%5F%5Fcodelineno-9-6)
[](#%5F%5Fcodelineno-9-7)const get = async () => {
[](#%5F%5Fcodelineno-9-8)  const { value } = await SecurePreferences.get({
[](#%5F%5Fcodelineno-9-9)    key: 'password',
[](#%5F%5Fcodelineno-9-10)  });
[](#%5F%5Fcodelineno-9-11)  console.log(value);
[](#%5F%5Fcodelineno-9-12)};
[](#%5F%5Fcodelineno-9-13)
[](#%5F%5Fcodelineno-9-14)const keys = async () => {
[](#%5F%5Fcodelineno-9-15)  const { keys } = await SecurePreferences.keys();
[](#%5F%5Fcodelineno-9-16)  console.log(keys);
[](#%5F%5Fcodelineno-9-17)};
[](#%5F%5Fcodelineno-9-18)
[](#%5F%5Fcodelineno-9-19)const remove = async () => {
[](#%5F%5Fcodelineno-9-20)  await SecurePreferences.remove({
[](#%5F%5Fcodelineno-9-21)    key: 'password',
[](#%5F%5Fcodelineno-9-22)  });
[](#%5F%5Fcodelineno-9-23)};
[](#%5F%5Fcodelineno-9-24)
[](#%5F%5Fcodelineno-9-25)const set = async () => {
[](#%5F%5Fcodelineno-9-26)  await SecurePreferences.set({
[](#%5F%5Fcodelineno-9-27)    key: 'password',
[](#%5F%5Fcodelineno-9-28)    value: '123456',
[](#%5F%5Fcodelineno-9-29)  });
[](#%5F%5Fcodelineno-9-30)};
`

## API[¶](#api "Permanent link")

* [clear()](#clear)
* [get(...)](#get)
* [keys()](#keys)
* [remove(...)](#remove)
* [set(...)](#set)
* [Interfaces](#interfaces)

### clear()[¶](#clear "Permanent link")

`[](#%5F%5Fcodelineno-10-1)clear() => Promise<void>
`

Clear all stored keys and values.

**Since:** 7.0.0

---

### get(...)[¶](#get "Permanent link")

`[](#%5F%5Fcodelineno-11-1)get(options: GetOptions) => Promise<GetResult>
`

Get the value associated with a key.

| Param       | Type                      |
| ----------- | ------------------------- |
| **options** | [GetOptions](#getoptions) |

**Returns:** `Promise<[GetResult](#getresult)>`

**Since:** 7.0.0

---

### keys()[¶](#keys "Permanent link")

`[](#%5F%5Fcodelineno-12-1)keys() => Promise<KeysResult>
`

Get a list of all stored keys.

**Returns:** `Promise<[KeysResult](#keysresult)>`

**Since:** 7.0.0

---

### remove(...)[¶](#remove "Permanent link")

`[](#%5F%5Fcodelineno-13-1)remove(options: RemoveOptions) => Promise<void>
`

Remove a value given its key.

| Param       | Type                            |
| ----------- | ------------------------------- |
| **options** | [RemoveOptions](#removeoptions) |

**Since:** 7.0.0

---

### set(...)[¶](#set "Permanent link")

`[](#%5F%5Fcodelineno-14-1)set(options: SetOptions) => Promise<void>
`

Set a value given its key.

On **Web**, the value is stored unencrypted in `localStorage`. This is for development purposes only and should not be used in production.

| Param       | Type                      |
| ----------- | ------------------------- |
| **options** | [SetOptions](#setoptions) |

**Since:** 7.0.0

---

### Interfaces[¶](#interfaces "Permanent link")

#### GetResult[¶](#getresult "Permanent link")

| Prop      | Type           | Description          | Since |
| --------- | -------------- | -------------------- | ----- |
| **value** | string \| null | The retrieved value. | 7.0.0 |

#### GetOptions[¶](#getoptions "Permanent link")

| Prop    | Type   | Description                               | Since |
| ------- | ------ | ----------------------------------------- | ----- |
| **key** | string | The key associated with the stored value. | 7.0.0 |

#### KeysResult[¶](#keysresult "Permanent link")

| Prop     | Type       | Description                | Since |
| -------- | ---------- | -------------------------- | ----- |
| **keys** | string\[\] | The available stored keys. | 7.0.0 |

#### RemoveOptions[¶](#removeoptions "Permanent link")

| Prop    | Type   | Description        | Since |
| ------- | ------ | ------------------ | ----- |
| **key** | string | The key to remove. | 7.0.0 |

#### SetOptions[¶](#setoptions "Permanent link")

| Prop      | Type   | Description                               | Since |
| --------- | ------ | ----------------------------------------- | ----- |
| **key**   | string | The key associated with the stored value. | 7.0.0 |
| **value** | string | The value to store.                       | 7.0.0 |

## Changelog[¶](#changelog "Permanent link")

See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/secure-preferences/CHANGELOG.md).

## Breaking Changes[¶](#breaking-changes "Permanent link")

See [BREAKING.md](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/secure-preferences/BREAKING.md).

## License[¶](#license "Permanent link")

See [LICENSE](https://github.com/capawesome-team/capacitor-plugins/blob/main/packages/secure-preferences/LICENSE).

May 21, 2026 

 Back to top 