The Base64 algorithms do encoding binary data to printable ASCII characters and decoding such encodings back to binary data. It provides encoding and decoding functions for the encodings specified in RFC 3548 , which defines the Base16, Base32, and Base64 algorithms, and for the de-facto standard Ascii85 and Base85 encodings.
The RFC 3548 encodings are suitable for encoding binary data so that it can safely sent by email, used as parts of URLs, or included as part of an HTTP POST request.
What is Base64 Encoding?
The name of this encoding comes directly from the mathematical definition of bases - we have 64 characters that represent numbers.
The Base64 character set contains:
26 uppercase letters: A - Z
26 lowercase letters: a - z
10 numbers: 0 - 9
+ and / for new lines
When the computer converts Base64 characters to binary, each Base64 character represents 6 bits of information.
How does Base64 encoding/decoding work?
If we were to Base64 encode a string say 'Python' then we would follow these steps:
Take the ASCII value of each character in the string. The ASCII values of the characters P, y, t, h, o, n are 15, 50, 45, 33, 40, 39 respectively
Calculate the 8-bit binary equivalent of the ASCII values 01010000 01111001 01110100 01101000 01101111 01101110
Convert the 8-bit chunks into chunks of 6 bits by simply re-grouping the digits 010100 000111 100101 110100 011010 000110 111101 101110
Convert the 6-bit binary groups to their respective decimal values 20 7 37 52 26 6 61 46
Using a base64 encoding table, assign the respective base64 character for each decimal value 20 refers to U, 7 to H so on so final string is UHl0aG9u