mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-03-15 19:50:58 +00:00
fix: use direct buffers instead of converting to hex
This commit is contained in:
parent
2c294b56ab
commit
027a5a9332
@ -129,8 +129,8 @@ RSA encryption/decryption for the browser with webcrypto workarround
|
|||||||
Explanation:
|
Explanation:
|
||||||
- Convert JWK to PEM
|
- Convert JWK to PEM
|
||||||
- Load PEM with nodeForge
|
- Load PEM with nodeForge
|
||||||
- Convert msg buffer to nodeForge buffer
|
- Convert msg buffer to nodeForge buffer: it's already uint8array, so do nothing
|
||||||
- Convert resulting nodeForge buffer to buffer
|
- 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) {
|
function convertKey (key, pub, msg, handle) {
|
||||||
const pem = jwkToPem(key)
|
const pem = jwkToPem(key)
|
||||||
const fkey = pki[pub ? 'publicKeyFromPem' : 'privateKeyFromPem'](pem)
|
const fkey = pki[pub ? 'publicKeyFromPem' : 'privateKeyFromPem'](pem)
|
||||||
const fmsg = forge.util.hexToBytes(Buffer.from(msg).toString('hex'))
|
const fomsg = handle(Buffer.from(msg), fkey)
|
||||||
const fomsg = handle(fmsg, fkey)
|
return Buffer.from(fomsg, 'binary')
|
||||||
return Buffer.from(forge.util.bytesToHex(fomsg), 'hex')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.encrypt = function (key, msg) {
|
exports.encrypt = function (key, msg) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user