Base64
- •
What it is
- •
An encoding that represents binary data as ASCII text using a 64-character alphabet (A-Z, a-z, 0-9, +, /), packing 3 bytes of input into 4 output characters (6 bits each), padded with
=to a multiple of 4. It's the standard way binary data gets embedded in text-based formats like email, HTML, JSON, and PEM.
- •
- •
When to apply
- •
Data made up of letters, digits,
+,/, and trailing=padding, usually in multiples of 4 characters.
- •
- •
Worked example
- •
base64.b64decode(base64.b64encode(b"crypto"))→b'crypto'; encoded form is"Y3J5cHRv".
- •
- •
Python
- •
import base64 encoded = base64.b64encode(b"crypto") # b'Y3J5cHRv' decoded = base64.b64decode(encoded) # b'crypto'
- •
- •
- •