Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: continue-dev
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 22 lines (16 sloc) 0.584 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
from Crypto.Cipher import AES
import base64
import os

class Crypt(object):
  BLOCKSIZE = 32
  
  def __init__(self, secret=os.urandom(BLOCKSIZE)):
    if len(secret) != self.BLOCKSIZE:
      raise Exception("Secret should be %s long, was %s" % \
              (self.BLOCKSIZE, len(secret)))
    self.secret = secret

  def prepare(self, data):
    encrypter = AES.new(self.secret, AES.MODE_CFB)
    return base64.b64encode(encrypter.encrypt(data))

  def unprepare(self, data):
    decrypter = AES.new(self.secret, AES.MODE_CFB)
    return decrypter.decrypt(base64.b64decode(data))

Something went wrong with that request. Please try again.