3Provides some helper methods for base 64 encoding.
10 """Decode a Base64 encoded string.
12 :param text: Base64 encoded string to decode
13 :return: Decoded string
15 missing_padding = len(text) % 4
17 text +=
"=" * (4 - missing_padding)
19 decoded = base64.urlsafe_b64decode(text)
20 return decoded.decode(
"utf-8")
23def encode_base_64(text: str) -> str:
24 """Encode a string to Base64.
26 :param text: String to encode
27 :return: Base64 encoded string
29 encoded_bytes = base64.urlsafe_b64encode(text.encode(
"utf-8")).rstrip(b
"=")
30 return encoded_bytes.decode(
"utf-8")
str decode_base_64(str text)
Decode a Base64 encoded string.