Created
May 20, 2021 21:25
-
-
Save GaetanoPiazzolla/4a83b86f3a42754cb6c659739b1020fe to your computer and use it in GitHub Desktop.
Overriding local and session storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related to medium article: https://medium.com/geekculture/how-to-encrypt-webstorage-in-angular-97094a0c5809