android中的Bas64为何缺少 ==

android中的Bas64为何缺少 ==

前言

在逆向xxxx哩App,寻找did参数生成方法时,发现如下代码生成的Base64编码与python模拟生成的结果差别在最后的两个==

java丢失了==python中有==

这里第二个参数传入的是11,不知道什么意思~
在这里插入图片描述

分析

生成代码如下:

Base64.encode(bytes, 11)

且其第二个参数flags传入的是11,然后查看导入的是哪个包的Base64,去找源代码看看

查看发现导入的是这个包中的Base64

import android.util.Base64;

其源码如下图所示
在这里插入图片描述
标志位说明:

flags说明注释flag
DEFAULTDefault values for encoder/decoder flags.默认模式0
NO_PADDINGEncoder flag bit to omit the padding ‘=’ characters at the end of the output (if any).省略末尾填充的’='字符1
NO_WRAPEncoder flag bit to omit all line terminators (i.e., the output will be on one long line).省略所有的终止符2
CRLFEncoder flag bit to indicate lines should be terminated with a CRLF pair instead of just an LF.指示行的编码器标志位用CRLF替代LF4
URL_SAFEEncoder/decoder flag bit to indicate using the “URL and filename safe” variant of Base64 (see RFC 3548 section 4) where - and _ are used in place of + and /.URL和文件名安全方式,替换其中不符合url安全的字符如+和/8
NO_CLOSEFlag to pass to Base64OutputStream to indicate that it should not close the output stream it is wrapping when it itself is closed.传递给Base64OutputStream标记以指示它本身关闭时不应关闭它正在包装的输出流16

所以

return new String(Base64.encode(bytes, 11));

中的,11=1+2+8,即:NO_PADDINGNO_WRAPURL_SAFE


版权声明:本文为dzdzdzd12347原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。