我经常听到人们谈论“64进制编码”。它的用途是什么?
当前回答
当需要对二进制数据进行编码时,通常使用Base64编码方案,这些数据需要通过设计用于处理文本数据的媒体存储和传输。这是为了确保数据在传输过程中保持完整而不被修改”(Wiki, 2017)
示例可能如下:您有一个只接受ASCII字符的web服务。你想要保存用户的数据,然后将其传输到其他位置(API),但接收者想要接收未触及的数据。Base64是用来…唯一的缺点是base64编码需要比常规字符串多33%的空间。
另一个示例::uenc = url encoded = aHR0cDovL2xvYy5tYWdlbnRvLmNvbS9hc2ljcy1tZW4tcy1nZWwta2F5YW5vLXhpaS5odG1s = http://loc.querytip.com/asics-men-s-gel-kayano-xii.html。
正如你所看到的,如果我们想把最后一次访问的URL作为参数发送,我们就不能把字符“/”放在URL中,因为我们会打破“MOD重写”- GET参数的属性/值规则。
一个完整的例子是:" http://loc.querytip.com/checkout/cart/add/uenc/http://loc.magento.com/asics-men-s-gel-kayano-xii.html/product/93/ "
其他回答
base64是一个二进制到文本的编码方案,以ASCII字符串格式表示二进制数据。Base64被设计用来跨通道传输二进制格式的数据。它接受任何形式的数据并将其转换为纯文本的长字符串。以前我们不能传输大量的数据,如文件,因为它是由2⁸比特字节组成的,但我们的实际网络使用2⁷比特字节。这就是base64编码出现的原因。但是base64到底是什么意思呢?
让我们来理解base64的含义。
base64 = base+64
我们可以调用base64作为基数64的表示。Base64仅使用6位(2 = 64个字符)来确保可打印的数据是人类可读的。但是,如何?我们也可以写base65或base78,但为什么只写64呢?让我们证明一下。 Base64编码包含64个字符来编码任何字符串。 base64包含:
10数值即,0,1,2,3,.....9。
26大写字母,即A,B,C,D,.......Z。
26个小写字母,即a,b,c,d,........z。
两个特殊字符,即+,/。取决于你的操作系统。
base64算法遵循的步骤如下:
count the number of characters in a String. If it is not multiple of 3 pad with special character i.e., = to make it multiple of 3. Encode the string in ASCII format. Now, it will convert the ASCII to binary format 8-bit each. After converting to binary format, it will divide binary data into chunks of 6-bits each. The chunks of 6-bit binary data will now be converted to decimal number format. Using the base64 Index Table, the decimals will be again converted to a string according to the table format. Finally, we will get the encoded version of our input string.
从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.
除了已经说过的,还有两种没有列出的非常常见的用法是
散列:
哈希是将一个字节块转换为另一个固定大小的字节块的单向函数,例如128bit或256bit (SHA/MD5)。将结果字节转换为Base64可以更容易地显示散列,特别是在比较完整性的校验和时。在Base64中经常看到哈希值,以至于许多人将Base64本身误认为是哈希值。
密码:
由于加密密钥不一定是文本,而是原始字节,因此有时需要将其存储在文件或数据库中,这在Base64中很方便。结果加密字节也是如此。
注意,尽管Base64经常用于密码学中,但它并不是一种安全机制。任何人都可以将Base64字符串转换回其原始字节,因此不应将其用作保护数据的手段,而应将其用作更容易显示或存储原始字节的格式。
证书
PEM格式的x509证书是base64编码的。http://how2ssl.com/articles/working_with_pem_files/
Base64可以用于许多目的。
主要原因是将二进制数据转换为可通过的数据。
我有时用它来将JSON数据从一个站点传递到另一个站点,存储信息 在cookie中关于用户的信息。
注意: 你“可以”用它来加密——我不明白为什么人们说你不能,而且它不是加密,尽管它很容易被破解,而且不受欢迎。加密只不过是将一串数据转换为另一串数据,以后可以解密,也可以不解密,这就是base64所做的。
对Brad所说的进行一点扩展:许多电子邮件和Usenet的传输机制以及其他移动数据的方式都不是“8位干净”的,这意味着标准ascii字符集之外的字符可能在传输中被破坏——例如,0x0D可能被视为回车符,并被转换为回车符和换行符。64进制将所有二进制字符映射为几个标准ascii字母、数字和标点符号,这样它们就不会被打乱。
推荐文章
- 可能增加的最坏的空间使用量是多少?
- 为什么PHP的json_encode函数转换UTF-8字符串为十六进制实体?
- 我如何确定文件编码在OS X?
- Base64长度计算?
- “\d”在正则表达式中是数字吗?
- 使用Javascript的atob解码base64不能正确解码utf-8字符串
- 尝试将一个非属性列表对象设置为NSUserDefaults
- 如何将base64编码的映像保存到磁盘?
- 如何将Base64字符串转换为位图图像,以显示在一个ImageView?
- 用base64编码图像文件
- 如何在iOS上进行base64编码?
- URL方案/主机/路径中的“+”是否代表空格?
- HTML编码问题-显示“”字符而不是“ ”
- 在HTML中,我可以用✓做一个复选标记;. 有相应的x标记吗?
- 有人知道如何解码和编码Base64中的字符串使用Base64吗?