Created
July 8, 2016 10:18
-
-
Save makeev/f1f4f73c6c1b1632cfb2dd066b27c4da 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
import base64 | |
from settings import settings | |
from M2Crypto import RSA | |
def encrypt(raw): | |
pub_key_path = settings.PUB_KEY_PATH | |
write_rsa = RSA.load_pub_key(pub_key_path) | |
encrypted = write_rsa.public_encrypt(raw, RSA.pkcs1_padding) | |
return base64.b64encode(encrypted) | |
def decrypt(enc): | |
private_key_path = settings.PRIVATE_KEY_PATH | |
read_rsa = RSA.load_key(private_key_path) | |
msg = read_rsa.private_decrypt(enc, RSA.pkcs1_padding) | |
return base64.b64decode(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment