Skip to content

nixgram/crypto-browser-storage

Repository files navigation

Crypto Browser Storage

☢ A simple package for secure local storage data by encryption using Crypto.JS. Project generated with angular version 12.2.0, sou must need an Angular Project ( version >= 12.2.x )

How to use

  • Use npm i crypto-browser-storage
  • Inject to your component or service as Dependency Injection
  • Then you will be able to access crypto-browser-storage's library functions,
    • setCache
    • getCache
    • removeCacheByKey
    • clearAllCache

Angular Compatibility Version

  • For ng v12.x.x use npm i crypto-browser-storage@1.0.3
  • For ng v14.x.x use npm i crypto-browser-storage@1.4.0
  • For ng v15.x.x use npm i crypto-browser-storage@2.1.0
  • For ng v16.x.x use npm i crypto-browser-storage@3.0.0
  • For ng v17.x.x use npm i crypto-browser-storage@4.0.2

For Angular Version 17 (only) 🎉

Now you can provide your custom encryption key. To provide your custom encryption key you have to follow this instruction. Provide CRYPTO_HASH_KEY in app.module.ts.
Example:

providers: [
    ....
    CryptoBrowserStorageService,
    { provide: CRYPTO_HASH_KEY, useValue: 'YOUR_KEY_HERE' }
  ]


Sample Code Snippet


import { CryptoBrowserStorageService } from 'crypto-browser-storage';

export class AppComponent {

constructor(private cache: CryptoBrowserStorageService) {}


    tests() {
    
    this.cache.setCache("Posts1", [{"id": 1, "name": "Sample"}]);
    this.cache.setCache("Posts2", ["id", "name", "Sample"]);
    this.cache.setCache("Posts3", 3);
    this.cache.setCache("Posts5", {"id": 4, "name": "Sample"});
    
    // this.cache.removeCacheByKey("Posts1")
    
    console.log(this.cache.getCache("Posts1"))
    console.log(this.cache.getCache("Posts2"))
    console.log(this.cache.getCache("Posts3"))
    console.log(this.cache.getCache("Posts5"))

    this.cache.clearAllCache();
    
    }

}

End result of the following tests() method is bellow,


Screenshot 2021-10-30 204648

Screenshot 2021-10-30 205713