本文翻译自:Why does a base64 encoded string have an = sign at the end

I know what base64 encoding is and how to calculate base64 encoding in C#, however I have seen several times that when I convert a string into base64, there is an = at the end. 我知道什么是base64编码,以及如何在C#中计算base64编码,但是我已经看过好几次了,当我将字符串转换为base64时,最后会有一个=

A few questions came up: 提出了一些问题:

  1. Does a base64 string always end with = ? base64字符串是否总是以=结尾吗?
  2. Why does an = get appended at the end? 为什么在末尾添加=

#1楼

参考:https://stackoom.com/question/T1NN/为什么base-编码的字符串的末尾有-符号


#2楼

It's padding. 它是填充。 From http://en.wikipedia.org/wiki/Base64 : 从http://en.wikipedia.org/wiki/Base64 :

In theory, the padding character is not needed for decoding, since the number of missing bytes can be calculated from the number of Base64 digits. 从理论上讲,不需要填充字符,因为可以从Base64位数计算出丢失的字节数。 In some implementations, the padding character is mandatory, while for others it is not used. 在某些实现中,填充字符是强制性的,而对于其他实现则不使用。 One case in which padding characters are required is concatenating multiple Base64 encoded files. 需要填充字符的一种情况是串联多个Base64编码的文件。


#3楼

  1. No. 没有。
  2. To pad the Base64-encoded string to a multiple of 4 characters in length, so that it can be decoded correctly. 将Base64编码的字符串的长度填充为4个字符的倍数,以便可以正确对其进行解码。

#4楼

http://www.hcidata.info/base64.htm http://www.hcidata.info/base64.htm

Encoding "Mary had" to Base 64 将“ Mary had”编码为Base 64

In this example we are using a simple text string ("Mary had") but the principle holds no matter what the data is (eg graphics file). 在此示例中,我们使用一个简单的文本字符串(“ Mary had”),但是无论数据是什么(例如图形文件),该原理都成立。 To convert each 24 bits of input data to 32 bits of output, Base 64 encoding splits the 24 bits into 4 chunks of 6 bits. 为了将输入数据的每24位转换为32位输出,Base 64编码将24位拆分为4个6位的块。 The first problem we notice is that "Mary had" is not a multiple of 3 bytes - it is 8 bytes long. 我们注意到的第一个问题是“ Mary have”不是3字节的倍数-它是8字节长。 Because of this, the last group of bits is only 4 bits long. 因此,最后一组位只有4位长。 To remedy this we add two extra bits of '0' and remember this fact by putting a '=' at the end. 为了解决这个问题,我们添加了两个额外的位“ 0”,并在末尾添加“ =”来记住这一事实。 If the text string to be converted to Base 64 was 7 bytes long, the last group would have had 2 bits. 如果要转换为Base 64的文本字符串长7个字节,则最后一组将有2位。 In this case we would have added four extra bits of '0' and remember this fact by putting '==' at the end. 在这种情况下,我们将添加四个额外的位“ 0”,并通过在最后放置“ ==”来记住这一事实。


#5楼

1-No 1-不

2- As a short answer : The 65th character ("=" sign) is used only as a complement in the final process of encoding a message. 2-简短的回答:第65个字符(“ =”符号)仅在消息编码的最终过程中用作补充。

You will not have a '=' sign if your string has a multiple of 3 characters number, because Base64 encoding takes each three bytes (8bits) and represents them as four printable characters in the ASCII standard. 如果您的字符串具有3个字符的倍数,则不会有'='符号,因为Base64编码每三个字节(8位)占用一个字节,并将它们表示为ASCII标准中的四个可打印字符。

Details : 细节 :

(a) If you want to encode (a)如果要编码

ABCDEFG <=> [ ABC ] [ DEF ] [ G ABCDEFG <=> [ ABC ] [ DEF ] [ G

Base64 will deal(producing 4 characters) with the first block and the second (as they are complete) but for the third it will add a double == in the output in order to complete the 4 needed characters.Thus, the result will be QUJD REVG Rw== (without space) Base64将处理(产生4个字符)第一个块和第二个块(因为它们完成了),但是对于第三个块,它将在输出中添加一个double ==以完成所需的4个字符,因此结果将是QUJD REVG Rw == (无空格)

(b) If you want to encode... (b)如果您想编码...

ABCDEFGH <=> [ ABC ] [ DEF ] [ GH ABCDEFGH <=> [ ABC ] [ DEF ] [ GH

Similarly, it will add just a single = in the end of the output to get 4 characters the result will be QUJD REVG R0g= (without space) 同样,它将在输出末尾仅添加一个=以获得4个字符,结果将为QUJD REVG R0g = (无空格)


#6楼

It serves as padding . 它用作填充 。

A more complete answer is that a base64 encoded string doesn't always end with a = , it will only end with one or two = if they are required to pad the string out to the proper length. 一个更完整的答案是,如果要求使用base64编码的字符串将字符串填充到适当的长度,则它并不总是=结尾,而是仅以一个或两个=结尾。

为什么base64编码的字符串的末尾有=符号相关推荐

  1. Base64编码的字符串与图片的互转

    用Flex写了一个例子,图片(暂时仅支持png.jpg/jpeg)转成base64编码的字符串(默认取上传文件的后缀名,然后添加了"data:image/(png|gif|jpg|jpeg) ...

  2. [转载] python程序所需的图片通过base64编码成字符串放在代码中

    参考链接: 在Python中编码和解码Base64字符串 问题背景 python代码打包成exe可执行文件.问题是这个python程序执行时需要显示一张图片,这就意味着打包成exe后,也需要在exe同 ...

  3. 现代密码学—密码学基本编码实践 16进制向base64编码转换 等长16进制字符串异或 找出密钥并破解密文 python

    实验地点:E楼III区503 实验时间:11.17 一.实验室名称:攻防实验室 二.实验项目名称:密码学基本编码实践 三.实验学时:6学时 四.实验原理: Base64是网络上最常见的用于传输8Bit ...

  4. php和js中,utf-8编码转成base64编码

    1.php下转化base64编码 php中,文本文件的编码决定了程序变量的编码,比如以下代码在不同编码的php文件中,展示的效果也是不一样的 <?php$word = '严';echo base ...

  5. base64编码_几分钟看懂Base64编码原理

    Base64简介 Base64是基于64个可打印字符(小写字母a-z,大写字母A-Z,数字0-9,符号"+","/" 再加上作为垫字的"=" ...

  6. Base64编码解码

    Base64是网络上最常见的用于传输8Bit字节码的编码方式之一,Base64就是一种基于64个可打印字符来表示二进制数据的方法. 可用于网络传输二进制数据(图片,文件...),将二进制转为Base6 ...

  7. 【Java】Base64编码与解码

    1.概述 转载:http://www.ruanyifeng.com/blog/2008/06/base64.html 1.1. 昨天的<MIME笔记>中提到,MIME主要使用两种编码转换方 ...

  8. 密码学基础:Base64编码

    文章概述: 本文目的:写这篇文章的目的主要是整理下密码学中Base64的知识点,并把它们分享出来.并且帮助初探密码学的坛友们一步一步的用C语言将Base64的编码实现出来. 阅读方法:希望大家在浏览完 ...

  9. base64编码,原理是什么,有什么作用?

    base64到底是什么东西呢? Base64编码是网络上常见的用于传输8bit字节数据的一种编码方式之一 , 有些人和书本会将编码写成加密算法,这其实是欠妥的.因为任何人拿到编码后的数据都能转化成原始 ...

最新文章

  1. PortableApps的使用方法
  2. javaweb:servlet的多线程同步问题
  3. Python之web开发(一):python常用搭建网站的框架简介
  4. AtCoder AGC030F Permutation and Minimum (DP、计数)
  5. Rancher 2.5 正式发布,多项重大更新来袭!
  6. hibernate连接数据库配置
  7. 织梦index.php源代码,PHP网站目录程序(织梦 v5.7 二次开发)
  8. zxing 如何识别反转二维码
  9. mysql孤立锁_SQL Server解决孤立用户浅析
  10. 【全套完结】数字信号处理----全套Matlab实验报告【建议保存】
  11. 微软推送补丁的服务器叫什么,即将大规模推送: 微软介绍KB4023057易升补丁相关功能...
  12. python数据分析入门到实战 知了课堂 百度云_零基础入门Python数据分析,只需要看懂这一张图,附下载链接!...
  13. Vuex的基本使用及总结(超详细)
  14. css中的单位换算_关于网页中pt和px的单位换算!
  15. 到了公司git使用工作流
  16. ToolStrip控件的使用
  17. OCR文本识别,文本行检测技术。
  18. 对PhD一年级新生有什么建议?
  19. 一度智信|拼多多优惠券怎么取消
  20. 谷歌语言设置_如何设置您的Google主页以使用两种语言

热门文章

  1. 关于Objective-C 对象release操作的一个小问题探讨
  2. __proto__和prototype 1
  3. JDK 中的证书生成和管理工具 keytool
  4. 检测表单是否合法,为什么不能用n++的探讨
  5. java实现栈的数据结构
  6. 购买课程赠老男孩出版的签名新书啦!
  7. Linux shell编程中read参数说明
  8. 程序员初学者参考 ---懂得基础语法后如何做一个自己的case?
  9. bzoj 2437: [Noi2011]兔兔与蛋蛋
  10. 从SharePoint 2013迁移到SharePoint Online - 评估工具