digitalbazaar / forge

A native implementation of TLS in Javascript and tools to write crypto-based and network-heavy webapps
https://digitalbazaar.com/
Other
5.04k stars 777 forks source link

rsa decrypt error #739

Open creatxrgithub opened 4 years ago

creatxrgithub commented 4 years ago
let rsa =  forge.pki.rsa;
let keypair = rsa.generateKeyPair({bits: 2048, e: 0x10001});

let encrypted = keypair.publicKey.encrypt(forge.util.createBuffer('你我他','utf8'), 'RSAES-PKCS1-V1_5');
console.log(typeof encrypted); console.log('--------------');
let decrypted = keypair.privateKey.decrypt(encrypted, 'RSAES-PKCS1-V1_5');

output:

string
--------------
/app/node_modules/node-forge/lib/rsa.js:1563
    throw new Error('Encryption block is invalid.');
    ^

Error: Encryption block is invalid.

------

what's the problem ? thanks. what's the pr

human-user commented 3 years ago
let encrypted = keypair.publicKey.encrypt(forge.util.createBuffer('你我他','utf8').getBytes(), 'RSAES-PKCS1-V1_5');