mirror of
https://github.com/abdellahaski/AngularFirebaseVotingApp.git
synced 2025-12-08 11:19:56 +00:00
Full Project upgrade
This commit is contained in:
34
src/app/services/local-storage.service.ts
Normal file
34
src/app/services/local-storage.service.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import * as CryptoJS from 'crypto-js';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class LocalStorageService {
|
||||
private key = "AngularFirebaseVotingAPP_Key@0";
|
||||
|
||||
constructor() { }
|
||||
public saveData(key: string, value: string) {
|
||||
localStorage.setItem(key, this.encrypt(value));
|
||||
}
|
||||
|
||||
public getData(key: string) {
|
||||
let data = localStorage.getItem(key)|| "";
|
||||
return this.decrypt(data);
|
||||
}
|
||||
public removeData(key: string) {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
|
||||
public clearData() {
|
||||
localStorage.clear();
|
||||
}
|
||||
|
||||
private encrypt(txt: string): string {
|
||||
return CryptoJS.AES.encrypt(txt, this.key).toString();
|
||||
}
|
||||
|
||||
private decrypt(txtToDecrypt: string) {
|
||||
return CryptoJS.AES.decrypt(txtToDecrypt, this.key).toString(CryptoJS.enc.Utf8);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user