Secure Storage
This plugin gets, sets and removes key,value pairs from a device's secure storage.
Requires Cordova plugin: cordova-plugin-secure-storage
. For more info, please see the Cordova Secure Storage docs.
The browser platform is supported as a mock only. Key/values are stored unencrypted in localStorage.
Repo: https://github.com/Crypho/cordova-plugin-secure-storage
Installation
- Install the Cordova and Ionic Native plugins:
$ ionic cordova plugin add cordova-plugin-secure-storage $ npm install --save @ionic-native/secure-storage@4
- Add this plugin to your app's module
Supported platforms
- Android
- Browser
- iOS
- Windows
Usage
import { SecureStorage, SecureStorageObject } from '@ionic-native/secure-storage';
constructor(private secureStorage: SecureStorage) { }
...
this.secureStorage.create('my_store_name')
.then((storage: SecureStorageObject) => {
storage.get('key')
.then(
data => console.log(data),
error => console.log(error)
);
storage.set('key', 'value')
.then(
data => console.log(data),
error => console.log(error)
);
storage.remove('key')
.then(
data => console.log(data),
error => console.log(error)
);
});
Instance Members
create(store)
Creates a namespaced storage.
Param | Type | Details |
---|---|---|
store |
string
|
Returns: Promise<SecureStorageObject>
SecureStorageObject
Instance Members
get(key)
Gets a stored item
Param | Type | Details |
---|---|---|
key |
string
|
Returns: Promise<string>
set(key, value)
Stores a value
Param | Type | Details |
---|---|---|
key |
string
|
|
value |
string
|
Returns: Promise<any>
remove(key)
Removes a single stored item
Param | Type | Details |
---|---|---|
key |
string
|
Returns: Promise<string>
returns a promise that resolves with the key that was removed
keys()
Get all references from the storage.
Returns: Promise<string[]>
returns a promise that resolves with array of keys storage
clear()
Clear all references from the storage.
Returns: Promise<any>
secureDevice()
Brings up the screen-lock settings
Returns: Promise<any>