fix: unit tests

This commit is contained in:
montaghanmy
2023-04-07 11:01:19 +01:00
parent de0a2d2066
commit af980a139b
3 changed files with 65 additions and 3 deletions
+3 -3
View File
@@ -2,7 +2,7 @@ import { createDecipheriv } from "crypto";
import { CryptoResult } from ".";
const PREFIX = "encrypted_";
const DEFAULT_IV = "twake_constantiv";
// const DEFAULT_IV = Buffer.from("twake_constantiv", "utf-8");
export default {
decrypt,
@@ -25,9 +25,9 @@ function decrypt(data: string, encryptionKey: string): CryptoResult {
const salt = encryptedArray[1]
? Buffer.from(encryptedArray[1], "utf-8")
: Buffer.from("", "utf-8");
const iv = encryptedArray[2]
const iv = encryptedArray.length >= 3
? Buffer.from(encryptedArray[2], "base64")
: Buffer.from(DEFAULT_IV, "utf-8");
: Buffer.from("twake_constantiv", "utf-8");
const password = Buffer.concat([Buffer.from(encryptionKey, "hex"), salt], 32);
const decipher = createDecipheriv("AES-256-CBC", password, iv);