---
title: "Capacitor Secure Preferences: Encrypted Storage"
description: Securely store key/value pairs such as passwords, tokens or other sensitive information in your Capacitor app.
date: 
  created: 2025-05-01
  updated: 2026-07-10
authors:
  - robingenz
categories:
  - Announcements
  - Capacitor
  - SDKs
links:
  - Capacitor Secure Preferences: sdks/capacitor/secure-preferences.md
faq: true
---

# Capacitor Secure Preferences: Encrypted Storage

Need to store passwords, tokens, or other sensitive values in a Capacitor app without rolling your own encryption? The [Capacitor Secure Preferences plugin](../../sdks/capacitor/secure-preferences.md) is a drop-in replacement for the official [Capacitor Preferences](https://capacitorjs.com/docs/apis/preferences){:target="_blank"} plugin that stores key/value pairs securely. It provides cross-platform support for Android, iOS, and Web and is available to all Capawesome [Insiders](../../insiders/index.md).

<!-- more -->

Let's take a quick look at the [API](../../sdks/capacitor/secure-preferences.md#api) and how to use the plugin in your Capacitor app.

## Installation

To install the Capacitor Secure Preferences plugin, please refer to the [Installation](../../sdks/capacitor/secure-preferences.md/#installation) section in the plugin documentation.

## Usage

Let's take a look at the basic usage of the plugin. You can find the complete API reference in the [API](../../sdks/capacitor/secure-preferences.md#api) section of the documentation.

### Set a value

You can set a value using the [`set`](../../sdks/capacitor/secure-preferences.md#set) method:

```typescript
import { SecurePreferences } from '@capawesome-team/capacitor-secure-preferences';

const set = async () => {
  await SecurePreferences.set({
    key: 'password',
    value: '123456',
  });
};
```

The stored value can be any string. To store other types or more complex objects, you can use [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/
JSON/stringify){:target="_blank"} to convert them to a string before storing them and [`JSON.parse()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse){:target="_blank"} to convert them back to their original form after retrieving them.

???+ warning "No encryption on Web"

    On **Android** and **iOS**, the value will be encrypted and stored securely on the device. On **Web**, the value will be stored unencrypted in `localStorage` since the web platform does not provide a secure storage solution. This is for development purposes only and should not be used in production.

### Get a value

You can get a value using the [`get`](../../sdks/capacitor/secure-preferences.md#get) method:

```typescript
import { SecurePreferences } from '@capawesome-team/capacitor-secure-preferences';

const get = async () => {
  const { value } = await SecurePreferences.get({ key: 'password' });
  console.log(value); // 123456
};
```

This will decrypt the value and return it as a string.

### Remove a value

To remove a value, you can use the [`remove`](../../sdks/capacitor/secure-preferences.md#remove) method:

```typescript
import { SecurePreferences } from '@capawesome-team/capacitor-secure-preferences';

const remove = async () => {
  await SecurePreferences.remove({ key: 'password' });
};
```

### Clear all values

If you want to clear all values, simply call the [`clear`](../../sdks/capacitor/secure-preferences.md#clear) method:

```typescript
import { SecurePreferences } from '@capawesome-team/capacitor-secure-preferences';

const clear = async () => {
  await SecurePreferences.clear();
};
```

### Get all keys

And finally, if you want to get all stored keys, you can use the [`keys`](../../sdks/capacitor/secure-preferences.md#keys) method:

```typescript
import { SecurePreferences } from '@capawesome-team/capacitor-secure-preferences';

const getAllKeys = async () => {
  const { keys } = await SecurePreferences.keys();
  console.log(keys); // ['password']
};
```

## FAQ

### Which platforms does the Capacitor Secure Preferences plugin support?

The plugin supports Android, iOS, and the Web. On Android and iOS values are encrypted and stored securely; on the Web they fall back to unencrypted `localStorage` (see below).

### Is the stored data encrypted on every platform?

No. On **Android** and **iOS** values are encrypted and stored securely on the device. On the **Web** there is no secure storage API, so values are kept unencrypted in `localStorage` — intended for development only, not production.

### Is it a drop-in replacement for @capacitor/preferences?

Yes. It mirrors the official [Capacitor Preferences](https://capacitorjs.com/docs/apis/preferences){:target="_blank"} API — `set`, `get`, `remove`, `clear`, and `keys` — so you can swap it in with minimal changes.

### Can I store objects instead of plain strings?

Values are stored as strings. Use `JSON.stringify()` before storing an object and `JSON.parse()` after reading it back.

## Related Posts

- [Alternative to the Ionic Identity Vault plugin](./alternative-to-ionic-identity-vault-plugin.md)
- [Alternative to the Ionic Secure Storage plugin](./alternative-to-ionic-secure-storage-plugin.md)
- [Exploring the Capacitor Secure Preferences API](./exploring-the-capacitor-secure-preferences-api.md)
- [Capacitor Biometrics plugin: Face & fingerprint authentication](./announcing-the-capacitor-biometrics-plugin.md)
- [Capacitor Vault plugin: store secrets securely](./announcing-the-capacitor-vault-plugin.md)

## Conclusion

The [Capacitor Secure Preferences plugin](../../sdks/capacitor/secure-preferences.md) gives you encrypted key/value storage on Android and iOS behind the familiar Preferences API, so securing tokens and other sensitive values is mostly a matter of swapping the import. Check the [API Reference](../../sdks/capacitor/secure-preferences.md#api) for the full method list.

**Missing a feature?** [Create a feature request](https://github.com/capawesome-team/capacitor-plugins/issues/new/choose){:target="_blank"} in our [GitHub repository](https://github.com/capawesome-team/capacitor-plugins){:target="_blank"}.

Join the Capawesome [Discord](https://discord.gg/VCXxSVjefW){:target="_blank"} server for questions and subscribe to the Capawesome [newsletter](https://capawesome.io/newsletter/){:target="_blank"} to stay updated.
