且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用RSA_set0_key(key,n,e,d)时RSA_public_decrypt失败?

更新时间:2021-11-21 22:50:49

可以使用N,E,D的RSA_set0_key()吗?

RSA_set0_key() with N, E, D is possible?

是的. OpenSSL手册页中记录了 RSA_set0_key .它的签名是:

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);

说明是:

可以通过调用RSA_set0_key()并将n,e和d的新值作为参数传递给函数来设置n,e和d参数值.第一次在给定的RSA对象上调用此函数时,值n和e必须为非NULL.值d可以为NULL.在随后的调用中,这些值中的任何一个都可以为NULL,这意味着相应的RSA字段保持不变.调用此函数会将值的内存管理转移到RSA对象,因此,调用此函数后,调用者不应释放已传递的值.

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和RSA_set0_crt_params()在成功时返回1,在失败时返回0.

RSA_set0_key(), RSA_set0_factors and RSA_set0_crt_params() return 1 on success or 0 on failure.


我使用RSA_set0_key进行密钥(N,E,D)设置,并且RSA_private_encrypt可以,但是RSA_public_decrypt总是失败

I use RSA_set0_key for key(N, E, D) setting, and RSA_private_encrypt is OK, but RSA_public_decrypt fails always

很难说出您使用RSA_public_decrypt是怎么回事.也许您可以添加一些代码,说明返回值是什么,并在函数失败时说明ERR_get_err的值.

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.

同时,您可能需要RSA对象具有扩展的私钥参数,例如pqdpdqqInv.这些是中国剩余定理(CRT)参数,并使用进行设置RSA_set0_crt_params .另请参阅无法在没有中国剩余定理因素的情况下进行解密?在OpenSSL用户邮件列表中.

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.