NodeJs, Crypto Error : “Error: error:0406B06E:rsa routines:RSA_padding_add_none:data too large for key size”

∥☆過路亽.° 提交于 2020-06-29 03:42:33

问题


I am getting error when I try to encrypt the data using crypto Module in nodejs.

I have tried disabling the padding also.

Error :Error: error:0406B06E:rsa routines:RSA_padding_add_none:data too large for key size

Code :-

const crypto = require('crypto');
const privateKey = '-----BEGIN PRIVATE KEY-----\nMIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAqPCzhHllwH/D1RWJ\noDso47Xe7N170rSBJPP7tC49wxf8OtR576SKlbHYmlbJmd2DtimNQkYhf1DbNA+G\ndlFn1QIDAQABAkEApidV58ydzp3aNRBhsz18Ebkl70BGMA1nlrh/rc5s4Bp1IeF5\nfM5iSTXcsMhzkBab8jgoFulffVhjhUOEdcZrAQIhANzM7CCymOhShScyWPfY0pP6\n08dVk5L2sTnYz2UG9MgtAiEAw99QK99gmZ8gd+7hvvlF/NG4GnI0U5lF/lXaUjPO\nf0kCIFUR1wAaD3OjJ44chc6oCSnef+3S+NKsnUeuUumXroPZAiEAu6BcscoGROHT\nPk+L2135Ftbl3h9r1HDMRXeD7J5HvlECIBcFryn4SxMuYS8xIFvq/viJmI7CL1Fh\nkeYmEpu8oxCS\n-----END PRIVATE KEY-----';
let data = {
    "name": "anand",
    "Hi": "Hisdcsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"
};
let buffer = Buffer.from(JSON.stringify(data));
let encrypted = crypto.privateEncrypt({
    key: privateKey,
    padding: crypto.constants.RSA_NO_PADDING
}, buffer);
console.log(encrypted.toString("base64"));

来源:https://stackoverflow.com/questions/62383753/nodejs-crypto-error-error-error0406b06ersa-routinesrsa-padding-add-none

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!