我经常听到人们谈论“64进制编码”。它的用途是什么?


当前回答

从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.

其他回答

Base64可以用于许多目的。

主要原因是将二进制数据转换为可通过的数据。

我有时用它来将JSON数据从一个站点传递到另一个站点,存储信息 在cookie中关于用户的信息。

注意: 你“可以”用它来加密——我不明白为什么人们说你不能,而且它不是加密,尽管它很容易被破解,而且不受欢迎。加密只不过是将一串数据转换为另一串数据,以后可以解密,也可以不解密,这就是base64所做的。

Base-64编码是一种获取二进制数据并将其转换为文本的方法,这样就更容易在电子邮件和HTML表单数据中传输。

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

大多数情况下,我看到它被用于在只能处理ascii或简单字符集的上下文中对二进制数据进行编码。

在计算机的早期,当电话线系统间的通信不是特别可靠时,一种快速而肮脏的验证数据完整性的方法被使用:“位奇偶校验”。在这种方法中,传输的每个字节都有7位数据,第8位将是1或0,以强制字节中1位的总数为偶数。

因此,0x01将作为0x81传输;0x02将是0x82;0x03仍然是0x03等等。

为了进一步完善这个系统,当定义ASCII字符集时,只有00-7F被分配字符。(直到今天,所有设置在80-FF范围内的字符都是非标准的)

当时的许多路由器都把奇偶校验和字节转换放在硬件中,迫使连接到它们的计算机严格处理7位数据。这迫使电子邮件附件(以及所有其他数据,这就是为什么HTTP和SMTP协议是基于文本的)转换为纯文本格式。

这些路由器很少能活到90年代。我非常怀疑它们中任何一个现在还在使用。

我要在这里描述的Base64的用法有点hack。所以如果你不喜欢黑客,请不要继续。

当我发现MySQL的utf8不支持4字节unicode字符时,我遇到了麻烦,因为它使用了3字节版本的utf8。那么我做了什么来支持完整的4字节unicode MySQL的utf8?base64在存储到数据库时编码字符串,在检索时解码字符串。

由于base64编码和解码非常快,上面的工作非常完美。

你需要注意以下几点:

Base64编码多使用33%的存储空间 存储在数据库中的字符串不是人类可读的(您可以将其作为数据库字符串使用基本加密形式的特性出售)。

对于任何不支持unicode的存储引擎,都可以使用上述方法。