This class provides a simple method to encrypt and decrypt text using
AES.
'''
- def __init__(self, password, salt='', key_length=16):
+ def __init__(self, password, salt='', key_length=128):
self.bs = AES.block_size
self.mode = AES.MODE_CBC
- self.key_length = key_length
+ if key_length not in [128, 256]:
+ raise Exception('Invalid key_length, only 128 and 256 allowed')
+ self.key_length = key_length/8
self.buf = ''
if salt:
self.salt = salt
def __init__(self, name, mode, comptype, fileobj, bufsize,
concat_stream=False, enctype='', password="",
- key_length=16):
+ key_length=128):
"""Construct a _Stream object.
"""
self._extfileobj = True
password = ''
# if not enctype there's no encryption
enctype = ''
- key_length = 16
+ key_length = 128
if filemode not in "rw":
raise ValueError("mode must be 'r' or 'w'")
comptype, enctype = comptype.split(".", 1)
kl = enctype[3:]
enctype = enctype[:3]
- key_length = 16 if kl == '128' else 32
+ key_length = 128 if kl == '128' else 256
password = kwargs.get('password', '')
if not password:
raise ValueError("you should give a password for encryption")