♻️Removed unused files and move unused encryption algorithm to co configuration (#513)

This commit is contained in:
Anton Shepilov
2024-05-07 18:24:53 +02:00
committed by GitHub
parent 24da0c8cfb
commit ac950f0e87
6 changed files with 7 additions and 128 deletions
+5 -2
View File
@@ -1,5 +1,8 @@
import { createCipheriv, createDecipheriv, createHash, randomBytes } from "crypto";
import { CryptoResult } from ".";
import config from "config";
const algorithm = config.get<string>("database.encryption");
export default {
encrypt,
@@ -14,7 +17,7 @@ function encrypt(
const key = createHash("sha256").update(String(encryptionKey)).digest("base64").substr(0, 32);
try {
const iv = options.disableSalts ? "0000000000000000" : randomBytes(16);
const cipher = createCipheriv("aes-256-cbc", key, iv);
const cipher = createCipheriv(algorithm, key, iv);
const encrypted = Buffer.concat([cipher.update(JSON.stringify(data)), cipher.final()]).toString(
"hex",
);
@@ -50,7 +53,7 @@ function decrypt(data: string, encryptionKey: any): CryptoResult {
try {
const encrypted = Buffer.from(encryptedArray[1], "hex");
const decipher = createDecipheriv("aes-256-cbc", key, iv);
const decipher = createDecipheriv(algorithm, key, iv);
const decrypt = JSON.parse(
Buffer.concat([decipher.update(encrypted), decipher.final()]).toString(),
);