From 48ac75b135d5485bf8607841d16ce9382c004517 Mon Sep 17 00:00:00 2001 From: wukko Date: Tue, 5 Mar 2024 21:02:29 +0600 Subject: [PATCH] crypto: concat buffers in encryptStream and decryptStream --- src/modules/sub/crypto.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/sub/crypto.js b/src/modules/sub/crypto.js index 7e312789..3f02edc5 100644 --- a/src/modules/sub/crypto.js +++ b/src/modules/sub/crypto.js @@ -13,7 +13,7 @@ export function encryptStream(str, iv, secret) { const key = scryptSync(Buffer.from(secret, "base64"), "salt", keyLength); const cipher = createCipheriv(algorithm, key, Buffer.from(iv, "base64")); - return Buffer.from(cipher.update(buff, "utf8", "binary") + cipher.final("binary"), "binary"); + return Buffer.concat([ cipher.update(buff), cipher.final() ]) } export function decryptStream(buf, iv, secret) { @@ -22,5 +22,5 @@ export function decryptStream(buf, iv, secret) { const key = scryptSync(Buffer.from(secret, "base64"), "salt", keyLength); const decipher = createDecipheriv(algorithm, key, Buffer.from(iv, "base64")); - return decipher.update(buff, "binary", "utf8") + decipher.final("utf8"); + return Buffer.concat([ decipher.update(buff), decipher.final() ]) }