Description
Implement Base64 encoding and decoding to convert binary data into a text-safe representation using 64 printable ASCII characters.
// binary → base64 string
byte_t to_base64(cbytes_t src, unsigned int src_len, bytes_t dst, unsigned long sizeof_dst);
// base64 string → binary
byte_t from_base64(cbytes_t b64, bytes_t dst, unsigned long sizeof_dst);
How it works
Every 3 bytes of input are split into 4 groups of 6 bits, each mapped to a character in the Base64 alphabet (A-Z, a-z, 0-9, +, /). Output is padded with = to align to 4-byte groups.
Use cases
- Embedding binary data in JSON / XML
- HTTP Basic Auth headers
- Email attachments (MIME)
- Data URIs
References
Description
Implement Base64 encoding and decoding to convert binary data into a text-safe representation using 64 printable ASCII characters.
How it works
Every 3 bytes of input are split into 4 groups of 6 bits, each mapped to a character in the Base64 alphabet (
A-Z,a-z,0-9,+,/). Output is padded with=to align to 4-byte groups.Use cases
References