Apache的Base64.encodeBase64和Android的Base64.encode与Base64.Default标志有什么区别吗?

Ale*_*scu 27 java base64 android apache-commons

示例A(使用org.apache.commons.codec.binary.Base64):

Base64.encodeBase64("foobar".getBytes()); 
Run Code Online (Sandbox Code Playgroud)

示例B(使用android.util.Base64):

Base64.encode("foobar".getBytes(), Base64.DEFAULT); 
Run Code Online (Sandbox Code Playgroud)

这些产生相同的字符串吗?

Ale*_*scu 79

不,不同之处在于,使用默认设置,Android的Base64包含行终止符.要获得与Apache编码相同的结果,请使用Base64.NO_WRAP.

  • 希望我能给你+100 upvotes. (9认同)
  • android.util.Base64.decode() 同样适用吗? (2认同)