def test_decrypt(self): key = 'A' * 32 iv = 'A' * 16 data = snowden1 block = 16 ciphertext, tag = _aes_encrypt(key, iv, data) fd = BytesIO() aes = _crypto.AESWriter(key, iv, fd, tag=tag) for i in range(len(ciphertext) / block): chunk = ciphertext[i * block:(i + 1) * block] aes.write(chunk) aes.end() cleartext_chunked = fd.getvalue() assert cleartext_chunked == data
def test_chunked_encryption(self): key = 'A' * 32 fd = BytesIO() aes = _crypto.AESWriter(key, _buffer=fd) iv = aes.iv data = snowden1 block = 16 for i in range(len(data) / block): chunk = data[i * block:(i + 1) * block] aes.write(chunk) aes.end() ciphertext_chunked = fd.getvalue() ciphertext, tag = _aes_encrypt(key, iv, data) assert ciphertext_chunked == ciphertext