SecureStorage is a TypeScript library that provides a secure storage wrapper around browser storage objects (e.g., localStorage
or sessionStorage
). It offers optional hashing, encryption, and decryption capabilities to protect sensitive data stored in the browser.
- Securely store data in browser storage.
- Optional hashing to obscure storage keys.
- Optional encryption to protect stored values.
- Optional decryption to retrieve stored values securely.
You can install SecureStorage via npm:
# Not yet published
npm install secure-storage
You can import the SecureStorage
class from the package:
import SecureStorage from 'secure-storage';
To create a secure storage instance, simply instantiate the SecureStorage
class with the desired storage object (e.g., localStorage
or sessionStorage
):
const secureStorage = new SecureStorage(localStorage);
You can store data securely using the setItem
method:
secureStorage.setItem('key', 'value');
You can retrieve stored data securely using the getItem
method:
const value = secureStorage.getItem('key');
You can remove data from the secure storage using the removeItem
method:
secureStorage.removeItem('key');
You can clear the entire secure storage using the clear
method:
secureStorage.clear();
Here's a simple example demonstrating how to use SecureStorage:
import SecureStorage from '@your-username/secure-storage';
// Create a secure storage instance
const secureStorage = new SecureStorage(localStorage);
// Store data securely
secureStorage.setItem('username', 'john_doe');
// Retrieve stored data securely
const username = secureStorage.getItem('username');
console.log('Username:', username); // Output: "john_doe"
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to open an issue or submit a pull request.
- This library was inspired by the need for secure client-side storage in web applications.
- Credit - secure-web-storage