Base64

Base64 describes a method of encoding 8 -bit binary data ( such as executable programs, zip files or images) to a string consisting of only readable, code page - independent ASCII characters. In connection with OpenPGP, a checksum (CRC -24) is still attached; this slightly modified method is called Radix -64.

It takes place in the Internet standard MIME ( Multipurpose Internet Mail Extensions ) application and is therefore mainly used for sending e - mail attachments. This is necessary to ensure the smooth transport of arbitrary binary data, since SMTP was designed in its original form only for the shipment of 7-bit ASCII characters. Through coding, the space requirement of the data stream increases by 33-36 % (33% by the coding itself, up to an additional 3 % due to the inserted in the encoded data stream line breaks ).

Procedure for coding

To encode the characters A- Z, a -z, 0-9, and / used and = at the end. Since these characters also occur in EBCDIC (Extended Binary Coded Decimal Interchange Code ) (albeit in other code positions), so that data exchange between non-ASCII platforms is also possible.

For encoding three bytes of the byte stream ( 24 bits) is divided into four 6 -bit blocks. Each of said 6-bit blocks forms a number from 0 to 63, these figures are based on the following conversion table in " printable ASCII characters " converted and output. The name of the algorithm can be explained by this very fact - each character of the encoded data stream can be a number from 0 to 63 assign ( see table). Mathematically, this resembles a value system of the base 64 As a rule, after every 76 characters output at the latest, which corresponds to 57 bytes encoded, inserted a line break, which is otherwise, however, for the coding of no concern.

If the total number of input bytes is not divisible by three, the text to be encoded is padded at the end with filling bytes consisting of zero bits so that a divisible by three the number of bytes results. To indicate to the decoder how many padding bytes are added, the 6-bit blocks that are formed from padding bytes correctly encoded with =. Thus, at the end of a Base64 -encoded file has zero, one or two = signs occur. In other words, it will be appended as many = characters as padding bytes have been added.

For a long n characters to be encoded text is the space requirement for the base64-encoded content ( without line breaks ) 4 * (n 2 - (( n 2 ) mod 3 )) / 3 characters. When using Abrundender integer division is the formula: .

In the event that the signs and / can not be used (for example, file names or URLs) will be described with " base64url " an incompatible modification. The signs and / are replaced by - ( minus, ASCII 2DHex ) and _ (underscore, ASCII 5Fhex ).

Example

Polyfon twittering birds ate Mäxchens beets, yogurt and cottage cheese The UTF- 8 encoded text is Base64 encoded to:

UG9seWZvbiB6d2l0c2NoZXJuZCBhw59lbiBNw6R4Y2hlbnMgVsO2Z2VsIFLDvGJlbiwgSm9n aHVydCB1bmQgUXVhcms = Recognizable here is that Base64 created an unreadable coding, in contrast, a quoted-printable -encoded text with the exception of special characters is at least partially legible.

Radix -64

----- BEGIN PGP MESSAGE -----   Version: GnuPG v1.4.10 (GNU / Linux)     jA0EAwMCxamDRMfOGV5gyZPnyX1BBPOQAE4BHbh7PfTDInn hXmnBr9D8 94 4 X5R   kNNl4E499Me3Fotq8/zvznEycz2h7vJ21SdP5akLhRPd4W1S79LoCvbZYh2x4t6x   Cnqev6S97ys4chOPgz0FePfKQos0I7 rrMSAc9 vXHmUCthFqp7FJJ7/D9bCfmdF   1qkYNhtk/P5uvZ0N2zAUsiScDJA =   = XXuR   ----- END PGP MESSAGE ----- The Base64 part ends with ... DJA =. This is followed by a line break, an equal sign and the base64 encoded CRC -24 checksum of the message.

107058
de