diff --git a/dist/services/CryptoService/CryptoServiceNode.js b/dist/services/CryptoService/CryptoServiceNode.js index ce4a0759403d821a8b1cab735018270232f73e0f..85eef9eb2e5510f8604bd45ab1da5a6b7074d434 100644 --- a/dist/services/CryptoService/CryptoServiceNode.js +++ b/dist/services/CryptoService/CryptoServiceNode.js @@ -48,10 +48,12 @@ const getBytes = (value, encoding) => { return bytes; }; class CryptoServiceNode { - encryptAESGCM(data) { + encryptAESGCM(data, key, iv) { return __awaiter(this, void 0, void 0, function* () { - const key = crypto.randomBytes(32); - const iv = crypto.randomBytes(12); + if (!key && !iv) { + key = crypto.randomBytes(32); + iv = crypto.randomBytes(12); + } const cipher = crypto.createCipheriv(AES_GCM_ALGO, key, iv); let encrypted; if (typeof data === "string") { diff --git a/src/services/CryptoService/CryptoServiceNode.ts b/src/services/CryptoService/CryptoServiceNode.ts index 6ac86277ca9bf332b389e55ad2eaa45b233489d2..1af2cca563ccbb8f960d1159f35762c743aa45a9 100644 --- a/src/services/CryptoService/CryptoServiceNode.ts +++ b/src/services/CryptoService/CryptoServiceNode.ts @@ -26,10 +26,15 @@ class CryptoServiceNode implements ICryptoService { public async encryptAESGCM(data: string): Promise<AESGCMOutput>; public async encryptAESGCM(data: ArrayBuffer): Promise<AESGCMOutput>; public async encryptAESGCM( - data: string | ArrayBuffer + data: string | ArrayBuffer, + key?: Buffer, + iv?: Buffer ): Promise<AESGCMOutput> { - const key = crypto.randomBytes(32); - const iv = crypto.randomBytes(12); + if (!key && !iv) { + key = crypto.randomBytes(32); + iv = crypto.randomBytes(12); + } + const cipher = crypto.createCipheriv(AES_GCM_ALGO, key, iv); let encrypted;