/hack/blockfs/cfs/encrwfs.py

https://bitbucket.org/arigo/arigo/ · Python · 18 lines · 13 code · 5 blank · 0 comment · 0 complexity · 53510fd1c194ae79d4fe6d9ab8442605 MD5 · raw file

  1. import md5
  2. from Crypto.Cipher import Blowfish
  3. from blockrwfs import BlockRWFS
  4. class EncryptedBlockRWFS(BlockRWFS):
  5. SECRETKEYSIZE = md5.digest_size
  6. def set_secret_key(self, secretkey):
  7. self.secretkey = secretkey
  8. def encrypt(self, data, salt=''):
  9. return Blowfish.new(self.secretkey,
  10. Blowfish.MODE_CBC, salt[:8]).encrypt(data)
  11. def decrypt(self, data, salt=''):
  12. return Blowfish.new(self.secretkey,
  13. Blowfish.MODE_CBC, salt[:8]).decrypt(data)