I'm getting the error "Error: error:0406C06E:rsa routines:RSA_padding_add_PKCS1_type_1:data too large for key size"
when I do:
var crypto = require('crypto');
var fs = require('fs');
var first_keys = {
public_key: fs.readFileSync('tests/public.key'),
private_key: fs.readFileSync('tests/private.key')
}
var first_result = crypto.privateEncrypt({
key: first_keys.private_key
}, new Buffer("Hello World!"));
var second_result = crypto.privateEncrypt({
key: first_keys.private_key
}, first_result);
var second_plaintext = crypto.publicDecrypt({
key: first_keys.public_key
}, second_result);
var first_plaintext = crypto.publicDecrypt({
key: first_keys.public_key
}, second_plaintext);
if(first_plaintext == new Buffer("Hello World!"))
console.log("Hello World!");
I know it is weird, but I'm creating a process that requires this to work for n iterations (private encrypting for n keys and public decrypting for n keys). I'm using a single key for testing purposes.