def encrypt_cbc(aes_key, content): iv = os.urandom(16) padder = PKCS7(AES.block_size).padder() padded_result = padder.update(content) + padder.finalize() aescbc = Cipher(AES(aes_key), CBC(iv)).encryptor() result = aescbc.update(padded_result) + aescbc.finalize() return result, iv