Base64 编码中可以有空格吗?
从base64编码生成的字符串中是否可能有空格('')?
Is it possible for a string generated from a base64 encoding to have a space (' ') in it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
不,下一个问题?
http://en.wikipedia.org/wiki/Base64#Variants_summary_table
实际上,空格和 CRLF 通常会被默默地跳过在解码期间,因为它们可能是由于分割长字符串而出现的。
No. Next question?
http://en.wikipedia.org/wiki/Base64#Variants_summary_table
Actually, spaces and CRLFs are usually silently skipped during the decoding, as they might appear as a result of splitting long strings.
通过阅读 http://en.wikipedia.org/wiki/Base64 wiki 似乎在允许并丢弃 MIME (RFC 2045) 空间的 Base64 传输编码。在所有其他变体中,它们都是被禁止的。啊...这个问题是重复的:Can a base64编码字符串包含空格?
By reading the http://en.wikipedia.org/wiki/Base64 wiki it seems that in Base64 transfer encoding for MIME (RFC 2045) spaces are allowed and discarded. In all other variants they are forbidden. Ah... and this question is a duplicate: Can a base64 encoded string contain whitespace?
我收到一个带有空格的 Base64 字符串,但我的解码器只是忽略了该空格。不幸的是,忽略空间并不能提供预期的价值。
空格(“”)必须替换为“+”,以便我的解码器输出正确的值。
I was receiving a base64 string with a space, but my decoder was just ignoring the space. Unfortunately ignoring the space was not providing the expected value.
The space (" ") had to be replaced with a "+" in order for my decoder output the correct value.
Base64 编码输出永远不会包含空格。 FooBabel 有一个基于 Apache Codec 的漂亮(免费)在线编码工具,您可以在其中使用换行符和行终止符等选项 - foobabel base64 编解码器
Base64 encoding output will never include a space. FooBabel has a nice (free) online encoding tool based on Apache Codec, where you can play with options like linebreaks and line terminators - foobabel base64 codec
我在调试vbscript代码时遇到了这个问题。
奇怪的是,MSFT 是这样编码的,而不是使用 + 进行编码,而是使用 ' '。 MIME 可以使用 s/ /+/g 修复,并且可以与 /usr/bin/base64 一起使用。
请注意,这是一种在 vbscript 中对文件进行编码的广为人知的模式,如果反向遵循,MSFT 将处理空格并放回相同的文件。 (它只是不能在其他地方互操作)
I came across this question when debugging vbscript code.
Oddly MSFT encodes like this, rather than encoding with a + it will use a ' '. The MIME can be fixed with s/ /+/g and it will work with /usr/bin/base64.
Note that this is a well advertised pattern for encoding a file in vbscript, and if followed in reverse it MSFT will deal with the spaces and put the same file back. (it just won't be interoperable elsewhere)
在使用 bash 的 Windows 上,编码是添加换行!需要抑制它。
$ echo -n "$OAUTH_CLIENT_SECRET" | $ echo -n "$OAUTH_CLIENT_SECRET" | 64位基数
V3E5SDFvSHVvdm5Nck5aUHBJQ3NValg5WGlKdXBua25MYWJuLUxiNXozclhTRWNLdDFDY09wSDhi
d2hNS3JMdA==
$ echo -n "$OAUTH_CLIENT_SECRET" | d2hNS3JMdA== $ echo -n "$OAUTH_CLIENT_SECRET" | base64 --换行 0
V3E5SDFvSHVvdm5Nck5aUHBJQ3NValg5WGlKdXBua25MYWJuLUxiNXozclhTRWNLdDFDY09wSDhid2hNS3JMdA==
On Windows using bash, the encoding is adding a line wrap! Need to suppress that.
$ echo -n "$OAUTH_CLIENT_SECRET" | base64
V3E5SDFvSHVvdm5Nck5aUHBJQ3NValg5WGlKdXBua25MYWJuLUxiNXozclhTRWNLdDFDY09wSDhi
d2hNS3JMdA==
$ echo -n "$OAUTH_CLIENT_SECRET" | base64 --wrap 0
V3E5SDFvSHVvdm5Nck5aUHBJQ3NValg5WGlKdXBua25MYWJuLUxiNXozclhTRWNLdDFDY09wSDhid2hNS3JMdA==