choucavalier
choucavalier

Reputation: 2770

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.

Upvotes: 3

Views: 1057

Answers (2)

Pelle
Pelle

Reputation: 1252

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

Upvotes: 2

shanet
shanet

Reputation: 7324

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/

Upvotes: 1

Related Questions