Created
January 23, 2019 17:04
-
-
Save yzdann/8524eaa2b39a8e4cff0651df99944eb3 to your computer and use it in GitHub Desktop.
fun with crypto lib in python
This file contains hidden or 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
from Crypto.PublicKey import RSA | |
from Crypto import Random | |
import ast | |
def newkeys(keysize): | |
random_generator = Random.new().read | |
key = RSA.generate(keysize, random_generator) | |
private, public = key, key.publickey() | |
return public, private | |
def encrypt(message, pub_key): | |
return pub_key.encrypt(message, 32) | |
def decrypt(message, private_key): | |
return private_key.decrypt(ast.literal_eval(str(message))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment