☢ 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
)
- 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
- For
ng v12.x.x
usenpm i [email protected]
- For
ng v14.x.x
usenpm i [email protected]
- For
ng v15.x.x
usenpm i [email protected]
- For
ng v16.x.x
usenpm i [email protected]
- For
ng v17.x.x
usenpm i [email protected]
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' }
]
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();
}
}