3

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.

2 Answers 2

2

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))
Sign up to request clarification or add additional context in comments.

1 Comment

if someone else confirms this works (i don't have the time to do it myself, it's an old project), i'll validate the answer
1

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/

2 Comments

Sorry, I know about m2crypto and I forgot to mention I wanted something python3 compatible. m2crypto is not ported to python3 and no one is really trying to it...
Ah, sorry, can't help you then. I wonder how difficult it would be to pull just the stuff you need from M2Crypto and make it compatible with Python 3. Probably more trouble than it's worth if I had to guess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.