I'm having a bit of trouble creating and using RSA keys from raw data.
I have the public exponent(e), public modulus(n), and private modulus(d).
Encryption seems to work (don't know for sure):
RSA* rsa = RSA_new();
rsa->e = BN_bin2bn(pubexp, pubexp_len, rsa->e);
rsa->n = BN_bin2bn(pubmod, pubmod_len, rsa->n);
result = RSA_public_encrypt(data_len, data, out, rsa, RSA_PKCS1_PADDING);
No errors at least.
Decryption seg faults without e and is incorrect with e:
RSA* rsa = RSA_new();
rsa->e = BN_bin2bn(pubexp, pubexp_len, rsa->e);
rsa->n = BN_bin2bn(pubmod, pubmod_len, rsa->n);
rsa->d = BN_bin2bn(prvmod, prvmod_len, rsa->d);
result = RSA_private_decrypt(data_len, data, out, rsa, RSA_PKCS1_PADDING);
Seems strange to seg fault, doesn't it know something is
missing/incorrect? Does RSA_new not initialize the structure to a
clean state? Wouldn't an error be appropriate here?
I assume it's missing some information about the private key. I
couldn't find an "RSA key from raw data" type function though the docs
say don't manipulate the internals directly (but give no
alternative). The docs says p, q, dmp1, dmq1, and iqmp are
unnecessary, correct?
Thanks for any pointers.
- How to create a RSA private key from raw data? Chris
- Re: How to create a RSA private key from raw data? Chris
- Re: How to create a RSA private key from raw d... Dr. Stephen Henson
- Re: How to create a RSA private key from r... Chris
- Re: How to create a RSA private key fr... Dr. Stephen Henson
- Re: How to create a RSA private key from raw d... Kyle Hamilton
- Re: How to create a RSA private key from r... Dr. Stephen Henson
- Re: How to create a RSA private key fr... Kyle Hamilton
- Re: How to create a RSA private k... Dr. Stephen Henson