from typing import Union
import base64


def b64_encode(data: Union[bytes, str]):
    """Base64 encode"""
    if isinstance(data, str):
        data = data.encode("utf-8")
    return base64.b64encode(data).decode("utf-8")