<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def getSymmetricallyEncryptedVal(val, secretKey: Union[str, bytes] = None) -> \ Tuple[str, str]: """ Encrypt the provided value with symmetric encryption :param val: the value to encrypt :param secretKey: Optional key, if provided should be either in hex or bytes :return: Tuple of the encrypted value and secret key encoded in hex """


    if isinstance(val, str):
        val = val.encode("utf-8")
    if secretKey:
        if isHex(secretKey):
            secretKey = bytes(bytearray.fromhex(secretKey))
        elif not isinstance(secretKey, bytes):
            error("Secret key must be either in hex or bytes")
        box = libnacl.secret.SecretBox(secretKey)
    else:
        box = libnacl.secret.SecretBox()

    return box.encrypt(val).hex(), box.sk.hex()