mirror of
https://github.com/abdellahaski/AngularFirebaseVotingApp.git
synced 2025-12-08 11:19:56 +00:00
35 lines
813 B
TypeScript
35 lines
813 B
TypeScript
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);
|
|
}
|
|
}
|