angulartypescriptencryption

Encrypting and Decryption Local storage values


In Angular, How to encrypt a value and store it in Local Storage and then Retrieve and Decrypt it.

Example

    a: Number = 5;
    b: Number = 6;
    c: Number;
    c= a+b;
    localStorage.setItem('result', (this.c)); // I wan to encrypt and store it in local storge here
    localStorage.getItem('result'); // I want to decrypt and get the value 

Which is the best way and how?


Solution

  • There are several ways do this but to decide which is best way to do? You need decide that what are trying to achieve with this encryption/decryption? Ideally, you can't secure local storage and it is not recommended to store any sensitive data in local storage. Couple of options to use store encrypted data in locals storage/

    other similar libraries