From 027a5a9332c5c3804bf5eb46b7bfa5c6c8067d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Kr=C3=BCger?= Date: Wed, 23 Oct 2019 13:33:48 +0200 Subject: [PATCH] fix: use direct buffers instead of converting to hex --- src/keys/rsa-browser.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/keys/rsa-browser.js b/src/keys/rsa-browser.js index 525ec1fe..7b524a33 100644 --- a/src/keys/rsa-browser.js +++ b/src/keys/rsa-browser.js @@ -129,8 +129,8 @@ RSA encryption/decryption for the browser with webcrypto workarround Explanation: - Convert JWK to PEM - Load PEM with nodeForge - - Convert msg buffer to nodeForge buffer - - Convert resulting nodeForge buffer to buffer + - Convert msg buffer to nodeForge buffer: it's already uint8array, so do nothing + - Convert resulting nodeForge buffer to buffer: it returns a binary string, turn that into a uint8array */ @@ -140,9 +140,8 @@ const jwkToPem = require('pem-jwk').jwk2pem function convertKey (key, pub, msg, handle) { const pem = jwkToPem(key) const fkey = pki[pub ? 'publicKeyFromPem' : 'privateKeyFromPem'](pem) - const fmsg = forge.util.hexToBytes(Buffer.from(msg).toString('hex')) - const fomsg = handle(fmsg, fkey) - return Buffer.from(forge.util.bytesToHex(fomsg), 'hex') + const fomsg = handle(Buffer.from(msg), fkey) + return Buffer.from(fomsg, 'binary') } exports.encrypt = function (key, msg) {