import base64


def _package_encrypted(encrypted, plain_len, crypt_iv):
    """Packages up the parameters into a base64 encoded string
    Args:
        encrypted(bytes, bytearray): an string representing encrypted data
        plain_len(int): the length of the plain text data
        crypt_iv(bytes, bytearray): the iv (initialization vector) value
    Return:
        A base64 string representing the data.
    Note:
        The strings are concatenated as 6 characters each for the length
        of the encrypted parameter and plain_len, followed by the encrypted
        parameter contents, and finally the iv value. The concatenated string
        is then base64 encoded and returned
    """
    if not isinstance(encrypted, (bytes, bytearray)):
        raise RuntimeError("Invalid encrypted text passed into _package_encrypted() - must be byte-like")

    encrypt_len = '{0:06d}'.format(len(encrypted))
    len_str = '{0:06d}'.format(plain_len)

    return base64.b64encode(encrypt_len.encode('utf-8') + len_str.encode('utf-8') + encrypted + \
                            crypt_iv).decode('utf-8')