#NEWLINE# def encrypt( key , msg , iv = None , alg = 'aes_128_cbc' , padding = 'PKCS#7' , b64enc = True , block_size = BLOCK_SIZE ) : #NEWLINE# #INDENT# '\n    :param key: The encryption key\n    :param iv: init vector\n    :param msg: Message to be encrypted\n    :param padding: Which padding that should be used\n    :param b64enc: Whether the result should be base64encoded\n    :param block_size: If PKCS#7 padding which block size to use\n    :return: The encrypted message\n    ' #NEWLINE# if ( padding == 'PKCS#7' ) : #NEWLINE# #INDENT# _block_size = block_size #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( padding == 'PKCS#5' ) : #NEWLINE# #INDENT# _block_size = 8 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# _block_size = 0 #NEWLINE# #UNINDENT# #UNINDENT# if _block_size : #NEWLINE# #INDENT# plen = ( _block_size - ( len ( msg ) % _block_size ) ) #NEWLINE# c = chr ( plen ) #NEWLINE# msg += ( c * plen ) #NEWLINE# #UNINDENT# ( cipher , iv ) = build_cipher ( tobytes ( key ) , iv , alg ) #NEWLINE# cmsg = ( iv + cipher . encrypt ( tobytes ( msg ) ) ) #NEWLINE# if b64enc : #NEWLINE# #INDENT# return b64encode ( cmsg ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return cmsg