rzcoder / node-rsa

Node.js RSA library
1.39k stars 205 forks source link

Does Node-RSA support standard RSA? #232

Open leo33853870 opened 8 months ago

leo33853870 commented 8 months ago

First, I am very sorry for my poor English!

I am writing program with node.js to test IC Card.

So I need to run standard RSA (encrypt and decrypt).

That is , RSA without padding , without random, without OAEP/PSS and so on. Thus , everytime I run RSA with the same key and datain, I expect the same dataout.

For example: hex N:(512 bit) 86fa9ba066685845fc03833a9699c8baefb53cfbf19052a7f10f1eaa30488cec1ceb752bdff2df9fad6c64b3498956e7dbab4035b4823c99a44cc57088a23783 hex E: 010001 hex D: 5d2f0dd982596ef781affb1cab73a77c46985c6da2aafc252cea3f4546e80f40c0e247d7d9467750ea1321cc5aa638871b3ed96d19dcc124916b0bcb296f35e1 hex datain: 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 When I run standard RSA encrypt , the dataout shall be : 750660AE819B9B900F863B1342EDE59180A8EBBA30678C9441C32AE536710A298D9D05D202E90FE137B2772B2D5FB08687FD213FF9CFDA80C1B1BA5873B6167A

And I write program like this, but it does not work. `var key = new NodeRSA({b: 512});

key.importKey({ n: Buffer.from('0086fa9ba066685845fc03833a9699c8baefb53cfbf19052a7f10f1eaa30488cec1ceb752bdff2df9fad6c64b3498956e7dbab4035b4823c99a44cc57088a23783', 'hex'), e: 65537, d: Buffer.from('5d2f0dd982596ef781affb1cab73a77c46985c6da2aafc252cea3f4546e80f40c0e247d7d9467750ea1321cc5aa638871b3ed96d19dcc124916b0bcb296f35e1', 'hex'), p: Buffer.from('00c59419db615e56b9805cc45673a32d278917534804171edcf925ab1df203927f', 'hex'), q: Buffer.from('00aee3f86b66087abc069b8b1736e38ad6af624f7ea80e70b95f4ff2bf77cd90fd', 'hex'), dmp1: Buffer.from('008112f5a969fcb56f4e3a4c51a60dcdebec157ee4a7376b843487b53844e8ac85', 'hex'), dmq1: Buffer.from('1a7370470e0f8a4095df40922a430fe498720e03e1f70d257c3ce34202249d21', 'hex'), coeff: Buffer.from('00b399675e5e81506b729a777cc03026f0b2119853dfc5eb124610c0ab82999e45', 'hex') }, 'components'); const publicComponents = key.exportKey('components-public'); //console.log(publicComponents);

var text = '11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111';

//key.setOptions({encryptionScheme:'pkcs1'}); var encrypted = key.encrypt(text, 'base64'); console.log('encrypted: ', encrypted); var b = Buffer.from(encrypted,'base64'); console.log('encrypted hex: ', b.toString('hex'));

var decrypted = key.decrypt(encrypted, 'utf8'); console.log('decrypted: ', decrypted);`

rsa