java Apache 的 Base64.encodeBase64 和带有 Base64.Default 标志的 Android 的 Base64.encode 之间有什么区别吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17912119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any difference between Apache's Base64.encodeBase64 and Android's Base64.encode with Base64.Default flag?
提问by Alex Florescu
Sample A (using org.apache.commons.codec.binary.Base64):
示例 A(使用 org.apache.commons.codec.binary.Base64):
Base64.encodeBase64("foobar".getBytes());
Sample B (using android.util.Base64):
示例 B(使用 android.util.Base64):
Base64.encode("foobar".getBytes(), Base64.DEFAULT);
Do these produce the same string?
这些会产生相同的字符串吗?
回答by Alex Florescu
No, the difference is that with the default settings, Android's Base64 includes line terminators. To obtain the same result as with the Apache encoding, use Base64.NO_WRAP.
不,不同之处在于默认设置下,Android 的 Base64 包含行终止符。要获得与 Apache 编码相同的结果,请使用 Base64.NO_WRAP。