The Base64 encoding is used to convert bytes that have binary or text data into ASCII characters. Encoding prevents the data from getting corrupted when it is transferred or processed through a text-only system. In this article, we will discuss about Base64 encoding and decoding and its uses to encode and decode binary and text data. Each Base64 character represents 6 bits of data. it is also important to note that it is not meant for encryption for obvious reasons.
import
base64
sample_string
=
"Hello world!"
sample_string_bytes
=
sample_string.encode(
"ascii"
)
base64_bytes
=
base64.b64encode(sample_string_bytes)
base64_string
=
base64_bytes.decode(
"ascii"
)
print
(
base64_string
)