Last active
March 28, 2018 07:19
-
-
Save lkdocs/6519328 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encrypt_RSA(public_key_loc, message): | |
''' | |
param: public_key_loc Path to public key | |
param: message String to be encrypted | |
return base64 encoded encrypted string | |
''' | |
from M2Crypto import RSA, BIO | |
key = open(public_key_loc, "r").read() | |
pubkey = str(key).encode('utf8') | |
bio = BIO.MemoryBuffer(pubkey) | |
rsa = RSA.load_pub_key_bio(bio) | |
encrypted = rsa.public_encrypt(message, RSA.pkcs1_oaep_padding) | |
return encrypted.encode('base64') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment