Java 中是否有使用 RFC 3548 的 base64 encode/decode 字符串库

Is there any library to base64 encode/decode strings using RFC 3548 in Java

我正在尝试解码 java 中的字符串。这个相同的字符串使用 RFC 3548 在外部系统中编码。我尝试了不同的库,例如 org.apache.commons.codec.binary.Base64,但正如预期的那样,存在不一致。似乎 apache 库正在使用 RFC 2045。有人可以帮我解决这个问题吗?此字符串不是静态的,并且在调用之间不断变化。

尝试 Apache Commons 库和 class

org.apache.commons.net.util.Base64

参见:http://commons.apache.org/proper/commons-codec/apidocs/org/apache/commons/codec/binary/Base64.html

下载地址:http://commons.apache.org/proper/commons-codec/download_codec.cgi

您可以使用 Google 的 Guava 库,

base64()

根据其 documentation,

The "base64" base encoding specified by RFC 4648 section 4 , Base 64 Encoding. (This is the same as the base 64 encoding from RFC 3548 .)

Download

有一个内置函数:

byte[] bytes = DatatypeConverter.parseBase64Binary(string);
String string = DatatypeConverter.printBase64Binary(bytes);

它也进行十六进制编码和其他一些事情。它旨在将数据编码到 XML 文档中。