Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3 OpenSSL binding of RSA_public_decrypt()

Is there any openssl binding in python 3.4 that binds the function RSA_public_decrypt() from libopenssl that allows us to decrypt stuff using a public key? For some reason, I need to do this in a project.

like image 869
valentin Avatar asked Mar 15 '26 17:03

valentin


2 Answers

I had the same problem, I found this slightly hacky (note the *.hazmat.* imports) solution

def do_decrypt_cryptography(message, private_key):
    from cryptography.hazmat.primitives import hashes
    from cryptography.hazmat.primitives.asymmetric import padding
    return private_key.decrypt(message,
                               padding.OAEP(mgf=padding.MGF1(algorithm=hashes.SHA1()),
                                            algorithm=hashes.SHA1(),
                                            label=None))
like image 72
Pelle Avatar answered Mar 18 '26 06:03

Pelle


Have you tried the M2Crypto library? It looks like the M2Crypto.RSA.RSA class has a public_decrypt(self, data, padding) function. M2Crypto is a Python wrapper for OpenSSL, but I'm not sure if that public_decrypt function directly calls the C OpenSSL RSA_public_decrypt() function. If you go that route, I'd double check the source to make sure.

http://www.heikkitoivonen.net/m2crypto/api/

like image 21
shanet Avatar answered Mar 18 '26 06:03

shanet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!