BASE64
In programming,
Base64 is a group of binary-to-text encoding schemes that represent binary data (more specifically, a sequence of 8-bit bytes) in an ASCII string format by translating the data into a radix-64 representation.
The term
Base64 originates from a specific MIME content transfer encoding.
Each non-final
Base64 digit represents exactly 6 bits of data.
Three bytes (i.e., a total of 24 bits) can therefore be represented by four
6-bit Base64 digits.
Common to all binary-to-text encoding schemes,
Base64 is designed to carry data stored in binary formats across channels that only reliably support text content.
Base64 is particularly prevalent on the World Wide Web where its uses include the ability to embed image files or other binary assets inside textual assets such as HTML and CSS files.
Base64 is also widely used for sending e-mail attachments.
This is required because SMTP - in its original form - was designed to transport
7-bit ASCII characters only.
This encoding causes an overhead of 33–36% (33% by the encoding itself; up to 3% more by the inserted line breaks).
The particular set of 64 characters chosen to represent the
64-digit values for the base varies between implementations.
The general strategy is to choose 64 characters that are common to most encodings and that are also printable.
This combination leaves the data unlikely to be modified in transit through information systems, such as email, that were traditionally not
8-bit clean.
For example,
MIME's Base64 implementation uses A-Z, a-z, and 0-9 for the first 62 values.
Other variations share this property but differ in the symbols chosen for the last two values; an example is
UTF-7.
The earliest instances of this type of encoding were created for dial-up communication between systems running the same OS, for example, uuencode for UNIX and BinHex for the
TRS-80 (later adapted for the Macintosh), and could therefore make more assumptions about what characters were safe to use.
For instance, uuencode uses uppercase letters, digits, and many punctuation characters, but no lowercase.
base64_encodeis designed to allow binary data transfer in 8-bit layers to be handled in layers that are not truly 8-bit.
This encoding function is designed to make binary data survive transport through transport layers that are not 8-bit clean, such as mail bodies.
The
Base64_encode data takes about 33% more space than the original data.
From Wikipedia, the free encyclopedia