RSA_set0_key() with N, E, D is possible?
Yes. RSA_set0_key
is documented in the OpenSSL man pages. Its signature is:
int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
The description is:
The n, e and d parameter values can be set by calling RSA_set0_key() and passing the new values for n, e and d as parameters to the function. The values n and e must be non-NULL the first time this function is called on a given RSA object. The value d may be NULL. On subsequent calls any of these values may be NULL which means the corresponding RSA field is left untouched. Calling this function transfers the memory management of the values to the RSA object, and therefore the values that have been passed in should not be freed by the caller after this function has been called.
Further down, under RETURN VALUES:
RSA_set0_key(), RSA_set0_factors and RSA_set0_crt_params() return 1 on success or 0 on failure.
I use RSA_set0_key for key(N, E, D) setting, and RSA_private_encrypt is OK, but RSA_public_decrypt fails always
Its hard to say what is going on with your use of RSA_public_decrypt
. Perhaps you can add some code, state what the return value is, and state the value of ERR_get_err
when the function fails.
In the meantime, you may need your RSA object to have the extended private key parameters, like p
, q
, dp
, dq
, and qInv
. Those are the Chinese Remainder Theorem (CRT) parameters, and they are set with RSA_set0_crt_params
. Also see Unable to decrypt without Chinese Remainder Theorem factors? on the OpenSSL users mailing list.