fosrl.pangolin/server/lib/crypto.ts

13 lines
410 B
TypeScript
Raw Permalink Normal View History

import CryptoJS from "crypto-js";
export function encrypt(value: string, key: string): string {
const ciphertext = CryptoJS.AES.encrypt(value, key).toString();
return ciphertext;
}
export function decrypt(encryptedValue: string, key: string): string {
const bytes = CryptoJS.AES.decrypt(encryptedValue, key);
const originalText = bytes.toString(CryptoJS.enc.Utf8);
return originalText;
}