secured-browser-storage
v1.0.0
Published
Store encrypted data in browser's storage like localStorage and sessionStorage
Downloads
14
Maintainers
Readme
secured-browser-storage
Module for securing browser's storage - local storage and session storage. Storing plain text in browser's storage could lead to security issues. For example, any user can change data stored in storage to change behaviour of application. Securing browser storage would implement one level of security (atleast not every user will be able to change stored data, this will require additional capabilities to alter data). Only application code would be able to read/write the browser's storage.
This module could be used in Angular, React or any other client side framework or library which supports 'npm modules'
Installation & Usage
npm i secured-browser-storage
Exposed methods
1. setStorageType(type: 'localStorage' | 'sessionStorage')
2. setItem(key: string, value: any)
3. getItem(key: string, defaultValue?: any)
4. removeItem(key: string)
5. clear()
6. config(secret: string, prefix?: string)
How to use
import { securedBrowserCache } from 'secured-browser-storage';
1. Set storage location ('localStorage' | 'sessionStorage'). Default storage is 'localStorage'
securedBrowserCache.setStorageType('sessionStorage'); // Store data in browser's session storage
2. Write encrypted value to browser's localstorage
securedBrowserCache.setItem('key', 'value');
3. Read encrypted value from browser's localstorage
const val = securedBrowserCache.getItem('key', 'default value')
4. Read selected key from storage
securedBrowserCache.removeItem('key');
5. Clear storage (Remove all keys)
securedBrowserCache.clear();
6. Set 'Secret Key' and 'Key Prefix'. This should be used to change default secret key and prefix
securedBrowserCache.config('new-secret-key', 'new-prefix-this-is-optional');
License
MIT
Collaborators
- Sunil Kumar
Steps to use module
npm install secured-browser-storage