Last active
October 22, 2018 05:38
-
-
Save lkdocs/6519270 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 Crypto.PublicKey import RSA | |
from Crypto.Cipher import PKCS1_OAEP | |
key = open(public_key_loc, "r").read() | |
rsakey = RSA.importKey(key) | |
rsakey = PKCS1_OAEP.new(rsakey) | |
encrypted = rsakey.encrypt(message) | |
return encrypted.encode('base64') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment