Base64 编码中可以有空格吗?

发布于 2024-10-19 15:37:14 字数 35 浏览 1 评论 0原文

从base64编码生成的字符串中是否可能有空格('')?

Is it possible for a string generated from a base64 encoding to have a space (' ') in it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

a√萤火虫的光℡ 2024-10-26 15:37:14

不,下一个问题?

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.

飞烟轻若梦 2024-10-26 15:37:14

通过阅读 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?

时光沙漏 2024-10-26 15:37:14

我收到一个带有空格的 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.

超可爱的懒熊 2024-10-26 15:37:14

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

满身野味 2024-10-26 15:37:14

我在调试vbscript代码时遇到了这个问题。

奇怪的是,MSFT 是这样编码的,而不是使用 + 进行编码,而是使用 ' '。 MIME 可以使用 s/ /+/g 修复,并且可以与 /usr/bin/base64 一起使用。

请注意,这是一种在 vbscript 中对文件进行编码的广为人知的模式,如果反向遵循,MSFT 将处理空格并放回相同的文件。 (它只是不能在其他地方互操作)

Function b64(fqfn)
   Dim inputStream: Set inputStream = CreateObject("ADODB.Stream")
   inputStream.Open
   inputStream.Type = 1
   inputStream.LoadFromFile(fqfn)

   Dim bytes: bytes = inputStream.Read

   Dim dom: Set dom = CreateObject("Microsoft.XMLDOM")
   Dim elem: Set elem = dom.createElement("tmp")
   elem.dataType = "bin.base64"
   elem.nodeTypedValue = bytes
   b64 = elem.text
End Function

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)

Function b64(fqfn)
   Dim inputStream: Set inputStream = CreateObject("ADODB.Stream")
   inputStream.Open
   inputStream.Type = 1
   inputStream.LoadFromFile(fqfn)

   Dim bytes: bytes = inputStream.Read

   Dim dom: Set dom = CreateObject("Microsoft.XMLDOM")
   Dim elem: Set elem = dom.createElement("tmp")
   elem.dataType = "bin.base64"
   elem.nodeTypedValue = bytes
   b64 = elem.text
End Function
红衣飘飘貌似仙 2024-10-26 15:37:14

在使用 bash 的 Windows 上,编码是添加换行!需要抑制它。
$ echo -n "$OAUTH_CLIENT_SECRET" | $ echo -n "$OAUTH_CLIENT_SECRET" | 64位基数
V3E5SDFvSHVvdm5Nck5aUHBJQ3NValg5WGlKdXBua25MYWJ​​uLUxiNXozclhTRWNLdDFDY09wSDhi
d2hNS3JMdA==

$ echo -n "$OAUTH_CLIENT_SECRET" | d2hNS3JMdA== $ echo -n "$OAUTH_CLIENT_SECRET" | base64 --换行 0
V3E5SDFvSHVvdm5Nck5aUHBJQ3NValg5WGlKdXBua25MYWJ​​uLUxiNXozclhTRWNLdDFDY09wSDhid2hNS3JMdA==

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==

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文