From 22588653ba9d9ebf330db36ee1690979f1ac418e Mon Sep 17 00:00:00 2001 From: Julen Diez Date: Fri, 31 Jan 2020 12:34:17 +0100 Subject: [PATCH] change encrypt3DES function --- src/api-redsys.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/api-redsys.js b/src/api-redsys.js index 1124ca1..1b61558 100644 --- a/src/api-redsys.js +++ b/src/api-redsys.js @@ -11,9 +11,10 @@ class Redsys { const iv = Buffer.alloc(8, 0); const cipher = crypto.createCipheriv('des-ede3-cbc', secretKey, iv); cipher.setAutoPadding(false); - return cipher.update(zeroPad(str, 8), 'utf8', 'base64') + - cipher.final('base64'); - } + const en_key = cipher.update(zeroPad(str, 8), 'utf8', 'binary') + cipher.final('binary'); + const l = Math.ceil(str.length / 8) * 8; + return Buffer.from(en_key.substr(0, l), 'binary').toString('base64'); +} decrypt3DES(str, key) { const secretKey = Buffer.from(key, 'base64');