我经常听到人们谈论“64进制编码”。它的用途是什么?
当前回答
在计算机的早期,当电话线系统间的通信不是特别可靠时,一种快速而肮脏的验证数据完整性的方法被使用:“位奇偶校验”。在这种方法中,传输的每个字节都有7位数据,第8位将是1或0,以强制字节中1位的总数为偶数。
因此,0x01将作为0x81传输;0x02将是0x82;0x03仍然是0x03等等。
为了进一步完善这个系统,当定义ASCII字符集时,只有00-7F被分配字符。(直到今天,所有设置在80-FF范围内的字符都是非标准的)
当时的许多路由器都把奇偶校验和字节转换放在硬件中,迫使连接到它们的计算机严格处理7位数据。这迫使电子邮件附件(以及所有其他数据,这就是为什么HTTP和SMTP协议是基于文本的)转换为纯文本格式。
这些路由器很少能活到90年代。我非常怀疑它们中任何一个现在还在使用。
其他回答
Base-64编码是一种获取二进制数据并将其转换为文本的方法,这样就更容易在电子邮件和HTML表单数据中传输。
http://en.wikipedia.org/wiki/Base64
当您有一些想要通过网络传送的二进制数据时,通常不会仅仅以原始格式在网络上传输比特和字节。为什么?因为有些媒体是为文本流而设计的。您永远不会知道——有些协议可能会将二进制数据解释为控制字符(如调制解调器),或者您的二进制数据可能会被搞糟,因为底层协议可能认为您输入了一个特殊的字符组合(如FTP如何转换行结束符)。
为了解决这个问题,人们把二进制数据编码成字符。Base64就是这些编码类型中的一种。
为什么是64年? 因为你通常可以依赖于相同的64个字符出现在许多字符集中,你可以合理地相信你的数据最终会在线路的另一端没有损坏。
对Brad所说的进行一点扩展:许多电子邮件和Usenet的传输机制以及其他移动数据的方式都不是“8位干净”的,这意味着标准ascii字符集之外的字符可能在传输中被破坏——例如,0x0D可能被视为回车符,并被转换为回车符和换行符。64进制将所有二进制字符映射为几个标准ascii字母、数字和标点符号,这样它们就不会被打乱。
从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.
这是一种二进制数据的文本编码,其结果文本除了字母、数字和符号“+”、“/”和“=”之外什么都没有。这是一种在专门用于文本数据的媒体上存储/传输二进制数据的方便方法。
但为什么是Base-64?将二进制数据转换为文本的两种替代方法是:
Decimal:将每个字节的十进制值存储为三个数字:045 112 101 037等,其中每个字节由3个字节表示。数据膨胀了三倍。 十六进制:将字节存储为十六进制对:AC 47 0D 1A等,其中每个字节由2个字节表示。数据膨胀了两倍。
Base-64在4个字符中映射3个字节(8 x 3 = 24位),该字符横跨6位(6 x 4 = 24位)。结果看起来像“TWFuIGlzIGRpc3Rpb…”。因此膨胀仅仅是原来的4/3 = 1.3333333倍。
推荐文章
- 如何将base64编码的映像保存到磁盘?
- 如何将Base64字符串转换为位图图像,以显示在一个ImageView?
- 用base64编码图像文件
- 如何在iOS上进行base64编码?
- URL方案/主机/路径中的“+”是否代表空格?
- HTML编码问题-显示“”字符而不是“ ”
- 在HTML中,我可以用✓做一个复选标记;. 有相应的x标记吗?
- 有人知道如何解码和编码Base64中的字符串使用Base64吗?
- 在UIImage和Base64字符串之间转换
- 如何检查一个字符串是否被Base64编码
- 如何保存一个PNG图像服务器端,从base64数据URI
- 如何存储自定义对象在NSUserDefaults
- 一个Unicode字符需要多少字节?
- 如何转换字符串和从UTF8字节数组在Java
- 如何确定文本的编码