What is base64 encoding used for?

后端 未结 18 738
滥情空心
滥情空心 2020-11-22 09:45

I\'ve heard people talking about \"base 64 encoding\" here and there. What is it used for?

相关标签:
18条回答
  • 2020-11-22 09:55

    It's basically a way of encoding arbitrary binary data in ASCII text. It takes 4 characters per 3 bytes of data, plus potentially a bit of padding at the end.

    Essentially each 6 bits of the input is encoded in a 64-character alphabet. The "standard" alphabet uses A-Z, a-z, 0-9 and + and /, with = as a padding character. There are URL-safe variants.

    Wikipedia is a reasonably good source of more information.

    0 讨论(0)
  • 2020-11-22 09:55

    Base-64 encoding is a way of taking binary data and turning it into text so that it's more easily transmitted in things like e-mail and HTML form data.

    http://en.wikipedia.org/wiki/Base64

    0 讨论(0)
  • 2020-11-22 09:56

    In the early days of computers, when telephone line inter-system communication was not particularly reliable, a quick & dirty method of verifying data integrity was used: "bit parity". In this method, every byte transmitted would have 7-bits of data, and the 8th would be 1 or 0, to force the total number of 1 bits in the byte to be even.

    Hence 0x01 would be transmited as 0x81; 0x02 would be 0x82; 0x03 would remain 0x03 etc.

    To further this system, when the ASCII character set was defined, only 00-7F were assigned characters. (Still today, all characters set in the range 80-FF are non-standard)

    Many routers of the day put the parity check and byte translation into hardware, forcing the computers attached to them to deal strictly with 7-bit data. This force email attachments (and all other data, which is why HTTP & SMTP protocols are text-based), to be convert into a text-only format.

    Few of the routers survived into the 90s. I severely doubt any of them are in use today.

    0 讨论(0)
  • 2020-11-22 09:57

    From http://en.wikipedia.org/wiki/Base64

    The term Base64 refers to a specific MIME content transfer encoding. It is also used as a generic term for any similar encoding scheme that encodes binary data by treating it numerically and translating it into a base 64 representation. The particular choice of base is due to the history of character set encoding: one can choose a set of 64 characters that is both part of the subset common to most encodings, and also printable. This combination leaves the data unlikely to be modified in transit through systems, such as email, which were traditionally not 8-bit clean.

    Base64 can be used in a variety of contexts:

    • Evolution and Thunderbird use Base64 to obfuscate e-mail passwords[1]
    • Base64 can be used to transmit and store text that might otherwise cause delimiter collision
    • Base64 is often used as a quick but insecure shortcut to obscure secrets without incurring the overhead of cryptographic key management

    • Spammers use Base64 to evade basic anti-spamming tools, which often do not decode Base64 and therefore cannot detect keywords in encoded messages.

    • Base64 is used to encode character strings in LDIF files
    • Base64 is sometimes used to embed binary data in an XML file, using a syntax similar to ...... e.g. Firefox's bookmarks.html.
    • Base64 is also used when communicating with government Fiscal Signature printing devices (usually, over serial or parallel ports) to minimize the delay when transferring receipt characters for signing.
    • Base64 is used to encode binary files such as images within scripts, to avoid depending on external files.
    • Can be used to embed raw image data into a CSS property such as background-image.
    0 讨论(0)
  • 2020-11-22 09:57

    Mostly, I've seen it used to encode binary data in contexts that can only handle ascii - or a simple - character sets.

    0 讨论(0)
  • 2020-11-22 09:58

    Base64 can be used for many purposes.

    The primary reason is to convert binary data to something passable.

    I sometimes use it to pass JSON data around from one site to another, store information in cookies about a user.

    Note: You "can" use it for encryption - I don't see why people say you can't, and that it's not encryption, although it would be easily breakable and is frowned upon. Encryption means nothing more than converting one string of data to another string of data that can be either later decrypted or not, and that's what base64 does.

    0 讨论(0)
提交回复
热议问题