Base64
Dan Tobias (Talk | contribs) (→Programming libraries/modules) |
|||
(2 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
{{FormatInfo | {{FormatInfo | ||
+ | |formattype=electronic | ||
|subcat=Transfer Encodings | |subcat=Transfer Encodings | ||
+ | |image=Base64.png | ||
}} | }} | ||
'''Base64''' is one of the two transfer encodings used in [[MIME]] e-mail messages to encode binary data entirely in characters of the 7-bit [[ASCII]] range so that it could be safely transmitted even through systems not supporting anything else (which was more of an issue in the 1970s when e-mail protocols were defined than at present). The other encoding is [[Quoted-printable]], which is best suited for data that is mostly ASCII text but may have a few "unsafe" characters needing encoding. Base64 is best suited for binary data where all byte values from 0 to 255 are likely to occur, and encodes them efficiently (but not easily readably by the "naked eye"). | '''Base64''' is one of the two transfer encodings used in [[MIME]] e-mail messages to encode binary data entirely in characters of the 7-bit [[ASCII]] range so that it could be safely transmitted even through systems not supporting anything else (which was more of an issue in the 1970s when e-mail protocols were defined than at present). The other encoding is [[Quoted-printable]], which is best suited for data that is mostly ASCII text but may have a few "unsafe" characters needing encoding. Base64 is best suited for binary data where all byte values from 0 to 255 are likely to occur, and encodes them efficiently (but not easily readably by the "naked eye"). | ||
Line 23: | Line 25: | ||
* RFC 4648 | * RFC 4648 | ||
− | == | + | == Software == |
− | * [http://www.base64encode.org/ | + | * [https://www.gnu.org/software/coreutils/coreutils.html GNU Coreutils] → [https://www.gnu.org/software/coreutils/manual/html_node/base64-invocation.html base64] |
− | + | * [http://www.base64encode.org/ Base64 online encoder/decoder] | |
− | + | ||
* [http://search.cpan.org/~gaas/MIME-Base64-3.14/Base64.pm Base64 module for Perl] | * [http://search.cpan.org/~gaas/MIME-Base64-3.14/Base64.pm Base64 module for Perl] | ||
Latest revision as of 16:52, 11 December 2015
Base64 is one of the two transfer encodings used in MIME e-mail messages to encode binary data entirely in characters of the 7-bit ASCII range so that it could be safely transmitted even through systems not supporting anything else (which was more of an issue in the 1970s when e-mail protocols were defined than at present). The other encoding is Quoted-printable, which is best suited for data that is mostly ASCII text but may have a few "unsafe" characters needing encoding. Base64 is best suited for binary data where all byte values from 0 to 255 are likely to occur, and encodes them efficiently (but not easily readably by the "naked eye").
A Base64-encoded message part is indicated in its MIME headers (following the Content-type header giving the type of data) with the line:
Content-Transfer-Encoding: Base64
The data is encoded as a sequence of base-64 digits, consisting of a character from a set of 64 characters, which (starting at the character representing zero) goes in the order:
- Capital letters from A to Z
- Lowercase letters from a to z
- Digits from 0 to 9
- The characters + and /
A base-64 digit (fitting in one byte of the encoded data) encodes six bits of the original data. Since a byte has eight bits, three bytes of the original file (24 bits) correspond to four base-64 digits. Thus, the encoding method requires you to consider each group of three bytes as a number (big-endian), and express it as four digits in the base-64 system. The padding character = is used to fill out a group of four characters if not needed to encode the end of the original data.
BinHex uses a similar encoding scheme (except for really early versions which used hexadecimal as implied by the name), but with a different set of 64 characters and some other format differences.