Base64 Encode

Base64 Encode

 

What is Base64 encoding

Base64 encoding represents a 6-bit binary string using a printable character (see Table D.1), where a 6-bit value of 0–25 represents an upper-case letter A–Z correspondingly; a 6-bit value of 26–51 represents a lower-case letter a–z correspondingly; a 6-bit value of 52–61 represents a digit 0–9 correspondingly; and the last two 6-bit values of 62 and 63 represent “+” and “/”, respectively. Transmitted in ASCII format, this means that every 6-bit string is replaced with an 8-bit string.

In addition, Base64 encoding uses the character “=” as a special indicator. Using Base64 encoding, a binary string is converted to a character string as follows:

Case 1: The binary data consists of only one byte. Pad it at the end with 16 0’s to extend it to a 24-bit string. This 24-bit string is then converted to a Base64 string of four characters, with “==” being the last two characters. This indicates that only the first two characters are to be decoded, and the suffix 0000 is discarded.

Case 2: The binary data consists of only two bytes. Pad it at the end with eight 0’s to extend it to a 24-bit string. This 24-bit string is then converted to a Base64 string of four characters, with “=” being the last character. This indicates that only the first three characters are to be decoded, and the suffix 00 is discarded.

Case 3: The binary data consists of at least three bytes. Place the first three bytes of the binary data into a 24-bit buffer, where the first byte is placed in the most significant eight bits of the buffer, the second byte is placed in the middle and the third byte in the least significant eight bits. This 24-bit string is then converted to a Base64 string of four characters. Repeat this process until there is no byte left, there is one byte left, or there are two bytes left. The conversion is completed if there is no byte left. If there is one byte left, apply Case 1 to this byte to complete the conversion. If there are two bytes left, apply Case 2 to these two bytes to complete the conversion.

Cookie
We care about your data and would love to use cookies to improve your experience.