-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
crypto.privateDecrypt - padding issue #9588
Comments
Can you provide a complete, simple, standalone example that reproduces the issue? |
I also would like you to confirm if you really set |
Alright, I'll look into this later today when I have time. |
Example: var crypto = require('crypto');
var path = require('path');
var constants = require('constants');
var fs = require('fs');
var privateEncryptString = function(str, key) {
var absolutePath = path.resolve(key);
var privateKey = fs.readFileSync(absolutePath, 'utf8');
var encrypted = crypto.privateEncrypt(
{
key: privateKey,
padding: constants.RSA_NO_PADDING
}, new Buffer(str));
return encrypted.toString('base64');
};
var hash = '122e4e90223ff56eb3490debebc64a17502e9025deb0ab56dcd2e4c67ef583f2';
var encypted = privateEncryptString(hash, './privatekey');
console.log(encypted); Running this produces the following error: Error: error:0406B07A:rsa routines:RSA_padding_add_none:data too small for key size Providing RSA_PKCS1_PADDING works as expected, RSA_PKCS1_OAEP_PADDING doesn't work either. (PKEY_RSA_CTRL:illegal or unsupported padding mode) |
A couple of things to note here:
So the |
Thanks for the info. I don't actually intend to use RSA_NO_PADDING though. Shouldn't RSA_PKCS1_OAEP_PADDING still work in the example I provided? |
@rensrongen Not with a private key. If you use a public key and |
Never mind, it's clarified! I was about to comment on the docs but I missed the last line of your previous comment. |
I've opened a separate issue for the docs: #9609 |
Dear friends, i have same problem but when i using RSA_PKCS1_PADDING, just the message can be decrypted(public-key) that they are encrypted(private-key) in 256 byte. some time encrypted message is 257 or 258 or 59 byte, then it failed to decryption. can you tell me whats my wrong and problem ? |
crypto.privateDecrypt
does not acceptRSA_PKCS1_OAEP_PADDING
andRSA_PKCS1_PADDING
option.Using either of them produces the following error:
It does accept
RSA_NO_PADDING
, but when I decrypt an sha256 signature, it will produce a 256 character string, the final 64 characters contained the actual hash.For example, I have to do the following to successfully decrypt and read the sha256 signature:
Everything works as expected when using
privateDecrypt
.The text was updated successfully, but these errors were encountered: