Skip to content

Instantly share code, notes, and snippets.

@lkdocs
Last active March 28, 2018 07:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lkdocs/6519382 to your computer and use it in GitHub Desktop.
Save lkdocs/6519382 to your computer and use it in GitHub Desktop.
def decrypt_RSA(private_key_loc, package):
'''
param: public_key_loc Path to your private key
param: package String to be decrypted
return decrypted string
'''
from base64 import b64decode
from M2Crypto import BIO, RSA
key = open(private_key_loc, "r").read()
priv_key = BIO.MemoryBuffer(key.encode('utf8'))
key = RSA.load_key_bio(priv_key)
decrypted = key.private_decrypt(b64decode(package), RSA.pkcs1_oaep_padding)
return decrypted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment