def build_cipher(key, iv, alg="aes_128_cbc"):
    """
    :param key: encryption key
    :param iv: init vector
    :param alg: cipher algorithm
    :return: A Cipher instance
    """
    typ, bits, cmode = alg.split("_")

    if not iv:
        iv = Random.new().read(AES.block_size)
    else:
        assert len(iv) == AES.block_size

    if bits not in ["128", "192", "256"]:
        raise AESError("Unsupported key length")
    try:
        assert len(key) == int(bits) >> 3
    except AssertionError:
        raise AESError("Wrong Key length")

    try:
        return AES.new(tobytes(key), POSTFIX_MODE[cmode], tobytes(iv)), iv
    except __HOLE__:
        raise AESError("Unsupported chaining mode")
dataset/ETHPy150Open rohe/pyoidc/src/oic/utils/aes.py/build_cipher