1625 if keysize not in AES.KeySize.values(): |
1625 if keysize not in AES.KeySize.values(): |
1626 raise ValueError("invalid key size: {0}".format(keysize)) |
1626 raise ValueError("invalid key size: {0}".format(keysize)) |
1627 # create a new iv using random data |
1627 # create a new iv using random data |
1628 iv = bytearray([i for i in os.urandom(16)]) |
1628 iv = bytearray([i for i in os.urandom(16)]) |
1629 moo = AESModeOfOperation() |
1629 moo = AESModeOfOperation() |
1630 mode, length, ciph = moo.encrypt(data, mode, key, keysize, iv) |
1630 _mode, _length, ciph = moo.encrypt(data, mode, key, keysize, iv) |
1631 # With padding, the original length does not need to be known. It's a bad |
1631 # With padding, the original length does not need to be known. It's a bad |
1632 # idea to store the original message length. |
1632 # idea to store the original message length. |
1633 # prepend the iv. |
1633 # prepend the iv. |
1634 return bytes(iv) + bytes(ciph) |
1634 return bytes(iv) + bytes(ciph) |
1635 |
1635 |