Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: use direct buffers instead of converting to hex
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 authored and jacobheun committed Oct 25, 2019
1 parent 2c294b5 commit 027a5a9
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/keys/rsa-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand All @@ -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) {
Expand Down

0 comments on commit 027a5a9

Please sign in to comment.