Skip to content

Instantly share code, notes, and snippets.

@freretuc
Created May 2, 2015 15:49
Show Gist options
  • Save freretuc/f5722cfc0b50c6278ae5 to your computer and use it in GitHub Desktop.
Save freretuc/f5722cfc0b50c6278ae5 to your computer and use it in GitHub Desktop.
Crypting with python
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
from requests import get
from base64 import b64encode
def encode(publickey, content):
rsakey = RSA.importKey(publickey)
rsakey = PKCS1_OAEP.new(rsakey)
return b64encode(rsakey.encrypt(content))
content = "secret"
publickey = open("public.pem","r")
crypted = encode(publickey, content)
print "Plain : " + content
print "Crypted : " + crypted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment