python如何调用libcrypto实现RSA解密?
黄舟
黄舟 2017-04-17 17:01:26
0
1
805
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
巴扎黑

This is completely the result of trial...
First of all, the base64 text needs to be converted

sign = base64.decodestring(sign)

Then the first input parameter of RSA_decrypt is wrong, it should be:

ret = RSA_private_decrypt(rsa_size, sign, rsa, key, 1)

See official website definition:

 int RSA_private_decrypt(int flen, unsigned char *from,
    unsigned char *to, RSA *rsa, int padding);

Here flen is the key length, which I thought was from_len before.
ret>0 means decryption is successful, the result is taken from rsa.value, and the fifth parameter is the padding mode, which should be RSA_PKCS1_PADDING, but this constant seems not to be found in libcrypto.so.6, I go from 0 to 5 I tried it out one by one. I guess 1 is RSA_PKCS1_PADDING and 2 is SSLV23_PADDING (not necessarily spelled this way). Because I have tried other libraries before, these two padding modes can be solved.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template