Skip to content

Instantly share code, notes, and snippets.

@Brick85
Created July 16, 2013 17:09
Show Gist options
  • Save Brick85/6010619 to your computer and use it in GitHub Desktop.
Save Brick85/6010619 to your computer and use it in GitHub Desktop.
python crypt and encrypt
from Crypto.Cipher import AES
from Crypto import Random
import base64
AESKEY = "jFa8*!9uiAS0!385&(lla$1dqae8#!da"
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s: s[0:-ord(s[-1])]
class AESCipher:
def encrypt(self, raw):
raw = pad(raw)
iv = Random.new().read(AES.block_size)
cipher = AES.new(AESKEY, AES.MODE_CBC, iv)
return base64.b64encode(iv + cipher.encrypt(raw))
def decrypt(self, enc):
enc = base64.b64decode(enc)
iv = enc[:16]
cipher = AES.new(AESKEY, AES.MODE_CBC, iv)
return unpad(cipher.decrypt(enc[16:]))
@Chandra405Chinna
Copy link

Hi...
How can i encrypt a folder which contains no. of files???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment