我经常听到人们谈论“64进制编码”。它的用途是什么?
当前回答
它用于将任意二进制数据转换为ASCII文本。
例如,电子邮件附件就是通过这种方式发送的。
其他回答
有些传输协议只允许传输字母数字字符。想象一下这样一种情况:控制字符用于触发特殊操作,或者每个字符只支持有限的位宽。Base64将任何输入转换为只使用字母数字字符、+、/和=作为填充字符的编码。
我要在这里描述的Base64的用法有点hack。所以如果你不喜欢黑客,请不要继续。
当我发现MySQL的utf8不支持4字节unicode字符时,我遇到了麻烦,因为它使用了3字节版本的utf8。那么我做了什么来支持完整的4字节unicode MySQL的utf8?base64在存储到数据库时编码字符串,在检索时解码字符串。
由于base64编码和解码非常快,上面的工作非常完美。
你需要注意以下几点:
Base64编码多使用33%的存储空间 存储在数据库中的字符串不是人类可读的(您可以将其作为数据库字符串使用基本加密形式的特性出售)。
对于任何不支持unicode的存储引擎,都可以使用上述方法。
当您有一些想要通过网络传送的二进制数据时,通常不会仅仅以原始格式在网络上传输比特和字节。为什么?因为有些媒体是为文本流而设计的。您永远不会知道——有些协议可能会将二进制数据解释为控制字符(如调制解调器),或者您的二进制数据可能会被搞糟,因为底层协议可能认为您输入了一个特殊的字符组合(如FTP如何转换行结束符)。
为了解决这个问题,人们把二进制数据编码成字符。Base64就是这些编码类型中的一种。
为什么是64年? 因为你通常可以依赖于相同的64个字符出现在许多字符集中,你可以合理地相信你的数据最终会在线路的另一端没有损坏。
Base64可以用于许多目的。
主要原因是将二进制数据转换为可通过的数据。
我有时用它来将JSON数据从一个站点传递到另一个站点,存储信息 在cookie中关于用户的信息。
注意: 你“可以”用它来加密——我不明白为什么人们说你不能,而且它不是加密,尽管它很容易被破解,而且不受欢迎。加密只不过是将一串数据转换为另一串数据,以后可以解密,也可以不解密,这就是base64所做的。
从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编码的映像保存到磁盘?
- 如何将Base64字符串转换为位图图像,以显示在一个ImageView?
- 用base64编码图像文件
- 如何在iOS上进行base64编码?
- URL方案/主机/路径中的“+”是否代表空格?
- HTML编码问题-显示“”字符而不是“ ”
- 在HTML中,我可以用✓做一个复选标记;. 有相应的x标记吗?
- 有人知道如何解码和编码Base64中的字符串使用Base64吗?
- 在UIImage和Base64字符串之间转换
- 如何检查一个字符串是否被Base64编码
- 如何保存一个PNG图像服务器端,从base64数据URI
- 如何存储自定义对象在NSUserDefaults
- 一个Unicode字符需要多少字节?
- 如何转换字符串和从UTF8字节数组在Java
- 如何确定文本的编码