Skip to content

Instantly share code, notes, and snippets.

@GaetanoPiazzolla
Created May 20, 2021 21:25
Show Gist options
  • Save GaetanoPiazzolla/4a83b86f3a42754cb6c659739b1020fe to your computer and use it in GitHub Desktop.
Save GaetanoPiazzolla/4a83b86f3a42754cb6c659739b1020fe to your computer and use it in GitHub Desktop.
Overriding local and session storage
Storage.prototype._setItem = Storage.prototype.setItem
Storage.prototype._getItem = Storage.prototype.getItem
Storage.prototype.setItem = function(key, value) {
this._setItem(key, CryptoJS.AES.encrypt(value, 'privatekey').toString())
}
Storage.prototype.getItem = function(key) {
let value = this._getItem(key)
if (value) {
return CryptoJS.AES.decrypt(value, 'privatekey').toString(CryptoJS.enc.Utf8)
} else {
return null
}
}
@GaetanoPiazzolla
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment