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
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))
1 Comment
choucavalier
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
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.
2 Comments
choucavalier
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...
shanet
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.