删除尾随" = QUOT;当base64编码 [英] Remove trailing "=" when base64 encoding

查看:138
本文介绍了删除尾随" = QUOT;当base64编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,每当我采用base64 EN code字符串,=是在末尾。我可以删除这个角色,后来再可靠德code将其加回,或者这是危险的?换句话说,就是=总是追加,或仅在某些情况下?

I am noticing that whenever I base64 encode a string, a "=" is appended at the end. Can I remove this character and then reliably decode it later by adding it back, or is this dangerous? In other words, is the "=" always appended, or only in certain cases?

我希望我的恩codeD string要尽可能短,这就是为什么我想知道如果我可以随时删除=字符,只是添加回解码之前。

I want my encoded string to be as short as possible, that's why I want to know if I can always remove the "=" character and just add it back before decoding.

感谢

推荐答案

= 是填充。

维基百科

这是额外的填充字符
  分配的可使用的强制
  带连接codeD输出成整数
  4个字符多个(或
  等效当unen codeD二进制
  文本是不为3字节的倍数);
  那么这些填充字符必须是
  解码时被丢弃,但仍
  允许有效的计算
  在unen codeD文本的长度,当其
  输入的二进制长度将不会是一个
  的3字节倍数(最后的非垫
  性格一般为EN codeD,以便
  在过去的6位块将其重新presents
  将零填补其至少
  显著位,至多两个垫
  字符可能在的结束发生
  EN codeD流)。

An additional pad character is allocated which may be used to force the encoded output into an integer multiple of 4 characters (or equivalently when the unencoded binary text is not a multiple of 3 bytes) ; these padding characters must then be discarded when decoding but still allow the calculation of the effective length of the unencoded text, when its input binary length would not be a multiple of 3 bytes (the last non-pad character is normally encoded so that the last 6-bit block it represents will be zero-padded on its least significant bits, at most two pad characters may occur at the end of the encoded stream).

如果你控制的另一端,你可以删除它时,在运输,然后重新插入(通过检查字符串长度)解码之前。结果
请注意,数据不会在传输有效的Base64。

If you control the other end, you could remove it when in transport, then re-insert it (by checking the string length) before decoding.
Note that the data will not be valid Base64 in transport.

这篇关于删除尾随" = QUOT;当base64编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆