mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2026-09-04 17:46:34 +02:00
22 lines
578 B
TypeScript
22 lines
578 B
TypeScript
import { Service } from 'typedi';
|
|
import { AES, enc } from 'crypto-js';
|
|
import { InstanceSettings } from './InstanceSettings';
|
|
|
|
@Service()
|
|
export class Cipher {
|
|
constructor(private readonly instanceSettings: InstanceSettings) {}
|
|
|
|
encrypt(data: string | object) {
|
|
const { encryptionKey } = this.instanceSettings;
|
|
return AES.encrypt(
|
|
typeof data === 'string' ? data : JSON.stringify(data),
|
|
encryptionKey,
|
|
).toString();
|
|
}
|
|
|
|
decrypt(data: string) {
|
|
const { encryptionKey } = this.instanceSettings;
|
|
return AES.decrypt(data, encryptionKey).toString(enc.Utf8);
|
|
}
|
|
}
|