def encryptData(key, data, mode=AESModeOfOperation.ModeOfOperation[u'CBC']):
 key = bytearray(key)
 if (mode == AESModeOfOperation.ModeOfOperation[u'CBC']):
  data = append_PKCS7_padding(data)
 keysize = len(key)
 assert (keysize in AES.KeySize.values()), u'invalid key size: {0}'.format(keysize)
 iv = bytearray([i for i in os.urandom(16)])
 moo = AESModeOfOperation()
 (mode, length, ciph) = moo.encrypt(data, mode, key, keysize, iv)
 return (bytes(iv) + bytes(ciph))

def encryptData ( key , data , mode = AESModeOfOperation . ModeOfOperation [ u'CBC' ] ) : key = bytearray ( key ) if ( mode == AESModeOfOperation . ModeOfOperation [ u'CBC' ] ) : data = append_PKCS7_padding ( data ) keysize = len ( key ) assert ( keysize in AES . KeySize . values ( ) ) , u'invalid key size: {0}' . format ( keysize ) iv = bytearray ( [ i for i in os . urandom ( 16 ) ] ) moo = AESModeOfOperation ( ) ( mode , length , ciph ) = moo . encrypt ( data , mode , key , keysize , iv ) return ( bytes ( iv ) + bytes ( ciph ) )
module function to encrypt the given data with the given key .