"Dance like no one is watching, encrypt like everyone is spying on you"
Has it happened to you that you want to save sensitive data at the frontend level? Or you do not want information that we commonly store in localstorage or sessionstorage to be intercepted by the user or even by attackers, because due to these problems we have decided to create a plugin to allow secure storage in a very simple way, where you will no longer have to worry about encryption, keys, etc.
To encrypt the information, AES of the CTR No Padding type is used, which is approved as part of the OWASP standards as a secure encryption algorithm, then it is saved to localStorage or sessionStorage depending on how you configure it in key/value format, for which the key is encrypted in MD5 and the value in AES CRT No Padding
$ npm i secured-storage --save
$ yarn add secured-storage
We can initialize the library with the following code:
import { SecuredStorage } from 'secured-storage';
SecuredStorage.initalize({
key: "r')[4Zkj<X+~^-YH" // The password is optional, if you do not send it, it is automatically generated following the strictest standards
});
To save securely you just have to call the "set" function, the first parameter is the key and the second parameter is the value, as shown in the following code example:
import { SecuredStorage } from 'secured-storage';
SecuredStorage.set("name", "Charlotte Smith");
To obtain a value and use the automatic decryption, just call the "get" function and it will return the value automatically
import { SecuredStorage } from 'secured-storage';
const name = SecuredStorage.get("name");
console.log(name); // Charlotte Smith
We can delete a record, specifying the value of its key
import { SecuredStorage } from 'secured-storage';
SecuredStorage.delete("name"); // This will permanently delete the name attribute
We can clean all the storage with a single command
import { SecuredStorage } from 'secured-storage';
SecuredStorage.clear(); // This will erase all storage permanently