Skip to content Skip to sidebar Skip to footer

What Is The Best Way To Encode String By Public-key In Python

Is there any way to encode string by public-key? I found two packages, pycrypto and m2crypto. But I can not find how to use them.

Solution 1:

To encode a string using public key:

#!/usr/bin/env python 
from M2Crypto import RSA, X509

x509 = X509.load_cert("recipient_cert.pem")
rsa = x509.get_pubkey().get_rsa()
print rsa.public_encrypt("your string to encrypt", RSA.pkcs1_oaep_padding)

Post a Comment for "What Is The Best Way To Encode String By Public-key In Python"