22 lines
510 B
TypeScript
22 lines
510 B
TypeScript
import * as CryptoJS from 'crypto-js';
|
|
import { parse } from 'flatted';
|
|
|
|
export class SymmetricCrypto {
|
|
private key: string;
|
|
|
|
constructor(key: string) {
|
|
this.key = key;
|
|
}
|
|
|
|
decrypt(encryptedData: string): object | null {
|
|
try {
|
|
const bytes = CryptoJS.AES.decrypt(encryptedData, this.key);
|
|
const decryptedData = bytes.toString(CryptoJS.enc.Utf8);
|
|
return parse(decryptedData);
|
|
} catch (error) {
|
|
console.error('Decryption failed:', error);
|
|
return null;
|
|
}
|
|
}
|
|
}
|