Skip to content

Instantly share code, notes, and snippets.

@kaminomisosiru
Last active June 26, 2017 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaminomisosiru/36527c0f072f03670d6dfe8736662854 to your computer and use it in GitHub Desktop.
Save kaminomisosiru/36527c0f072f03670d6dfe8736662854 to your computer and use it in GitHub Desktop.
decrypt RSA (PKCS1 OAEP)
# -*- coding : utf-8 -*-
def decrypt_RSA(private_key_loc, package):
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
from base64 import b64decode
key = open(private_key_loc, "r").read()
rsakey = RSA.importKey(key)
rsakey = PKCS1_OAEP.new(rsakey)
decrypted = rsakey.decrypt(b64decode(package))
return decrypted
package = open('flag.enc', "r").read()
message = decrypt_RSA('private87.key', package)
print (message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment