剥离填充后解码 Base64

发布于 2024-11-08 19:18:29 字数 210 浏览 2 评论 0原文

我正在从 Base64 编码字符串的末尾剥离填充。我发现我可以成功解码字符串,而无需首先添加填充(至少在 php 中)。这是 base64 规范的结果还是依赖于实现的结果?

还有一个相关的问题,除了作为填充之外,base64 编码的字符串中是否可以存在 = 符号,即如果它不依赖于实现,那么仅删除尾随的等号是否安全,或者是否有可能最后一个“真实”角色可能是一个吗?

I am stripping the padding from the end of of a base64 encoded string. I have found that I can successfully decode the string without adding the padding back on first (in php at least). Is this a result of the specification of base64 or implementation dependent?

And a related question, can a = sign exist in a base64 encoded string other than as padding, i.e. If it is not implementation dependent, is it safe just to strip the trailing equals signs or is it possible that the last "real" character could have been one?

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

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

发布评论

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

评论(1

鹊巢 2024-11-15 19:18:29

虽然解码 Base64 字符串不需要填充,但如果删除填充,某些实现会引发错误。

RFC 规定:

Implementations MUST include appropriate pad characters at the end of
   encoded data unless the specification referring to this document
   explicitly states otherwise.

= 字符仅用于填充。

While padding isn't necessary to decode a base64 string, there are some implementations that will throw an error if the padding has been stripped away.

The RFC states:

Implementations MUST include appropriate pad characters at the end of
   encoded data unless the specification referring to this document
   explicitly states otherwise.

The = character will only ever be used for padding.

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