12345678910111213141516171819202122232425 |
- def aes(key, data, counter=False):
- """ encrypt data with aes, using either pycryptopp or PyCrypto.
- Args
- key: The encryption key
- data: plain text data
- counter: a callable, usually not needed
- """
-
- if hasattr(AES, "process"):
- a = AES(key)
- return a.process(data)
-
- counter = counter or Counter()
- a = AES.new(key, AES.MODE_CTR, counter=counter)
- rest = len(data) % 16
- if not rest:
- return a.encrypt(data)
-
-
- pad = (16 - rest)
- data += chr(pad) * pad
- return a.encrypt(data)[:-pad]
-
|