Skip to content
Capacitor plugin for storing string values securly on iOS and Android.
Java Swift TypeScript Ruby Objective-C JavaScript
Branch: master
Clone or download
Latest commit 21f92c5 Jul 25, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
android Add clear method Jul 23, 2019
ios Add clear method Jul 23, 2019
src add prefix for web, update readme Jul 25, 2019
.gitignore add dist to .gitignore Jul 23, 2019
.npmignore Initial commit Jul 22, 2019
CapacitorSecureStoragePlugin.podspec increase version Jul 25, 2019
LICENSE Initial commit Jul 17, 2019
README.md add prefix for web, update readme Jul 25, 2019
package-lock.json Initial commit Jul 22, 2019
package.json increase version Jul 25, 2019
rollup.config.js Initial commit Jul 22, 2019
tsconfig.json Initial commit Jul 22, 2019

README.md

capacitor-secure-storage-plugin

Capacitor plugin for storing string values securly on iOS and Android.

How to install

npm install capacitor-secure-storage-plugin

Usage

In a component where you want to use this plugin add to or modify imports:

import 'capacitor-secure-storage-plugin';
import { Plugins } from '@capacitor/core';

const { SecureStoragePlugin } = Plugins;

First line is needed because of web part of the plugin (current behavior of Capacitor, this may change in future releases).

Methods

  • get(options: { key: string }): Promise<{ value: string }>
    • if item with specified key does not exist, throws an Error
  • set(options: { key: string; value: string }): Promise<{ value: boolean }>
  • remove(options: { key: string }): Promise<{ value: boolean }>
  • clear(): Promise<{ value: boolean }>
    • set, remove and clear return true in case of success and false in case of error

Example

const key = 'username';
const value = 'hellokitty2';

SecureStoragePlugin.set({ key, value })
  .then(success => console.log(success))
const key = 'username';
SecureStoragePlugin.get({ key })
  .then(value => {
    console.log(value);
  })
  .catch(error => {
    console.log('Item with specified key does not exist.');
  });
async getUsername(key: string) {
  return await SecureStoragePlugin.get({ key });
}

Platform specific information

iOS

This plugin uses SwiftKeychainWrapper under the hood for iOS.

Android

On Android it is implemented by AndroidKeyStore and SharedPreferences. Source: Apriorit

Warning

For Android API < 18 values are stored as simple base64 encoded strings.

Web

There is no secure storage in browser (not because it is not implemented by this plugin, but it does not exist at all). Values are stored in LocalStorage, but they are at least base64 encoded. Plugin adds 'capsec' prefix to keys to avoid conflicts with other data stored in LocalStorage.

You can’t perform that action at this time.