Skip to content

Instantly share code, notes, and snippets.

@strategicpause
Created November 7, 2017 15:55
Show Gist options
  • Save strategicpause/75e6cbad18355668b5c12f144279d349 to your computer and use it in GitHub Desktop.
Save strategicpause/75e6cbad18355668b5c12f144279d349 to your computer and use it in GitHub Desktop.
from Crypto.PublicKey import RSA
from Crypto import Random
from Crypto.Cipher import PKCS1_OAEP
from base64 import b64encode, b64decode
random_generator = Random.new().read
key = RSA.generate(1024, random_generator)
print(key.exportKey('PEM'))
cipher = PKCS1_OAEP.new(key)
ciphertext = b64encode(cipher.encrypt("Hello".encode("UTF8")))
print(ciphertext)
plaintext = cipher.decrypt(b64decode(ciphertext))
print(plaintext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment