♻️Removed unused files and move unused encryption algorithm to co configuration (#513)
This commit is contained in:
@@ -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(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user