java.util.Base64.getDecoder().decode 和 org.asynchttpclient.util.Base64.decode 有什么区别?
What is the difference between java.util.Base64.getDecoder().decode and org.asynchttpclient.util.Base64.decode?
我有一个 base64 编码的字符串,在 php 中编码,现在我必须解码为 java 中的原始字符串。
第一次尝试用java.util.Base64.getDecoder().decode(encodedString)
解码。
但它抛出 Illegal base64 character 25
。
经过多次尝试,我用org.asynchttpclient.util.Base64.decode(encodedString)
搞定了
但是,有什么区别呢?非常感谢!
根据文档:org.asynchttpclient.util.Base64
Implements the "base64" binary encoding scheme as defined by RFC 2045.
Portions of code here are taken from Apache Pivot
所以它是多用途 Internet 邮件扩展 (MIME) 的实现 RFC 2045
根据文档:java.util.Base64.getDecoder()
Returns a Base64.Decoder that decodes using the Basic type base64
encoding scheme.
Basic
Uses "The Base64 Alphabet" as specified in Table 1 of RFC 4648 and RFC 2045 for encoding and decoding operation. The encoder does not add any
line feed (line separator) character. The decoder rejects data that
contains characters outside the base64 alphabet.
java.util.Base64.getDecoder()
returns解码器根据RFC 4648。解码器拒绝包含 base64 字母表之外的字符的数据。它不是 MIME 实现。
要获得相同的行为,您需要使用 java.util.Base64.getMimeDecoder()
MIME
Uses the "The Base64 Alphabet" as specified in Table 1 of RFC 2045 for
encoding and decoding operation. The encoded output must be
represented in lines of no more than 76 characters each and uses a
carriage return '\r' followed immediately by a linefeed '\n' as the
line separator. No line separator is added to the end of the encoded
output. All line separators or other characters not found in the
base64 alphabet table are ignored in decoding operation.
MIME 编码器使用基本字母表生成 Base64 编码的输出。
每行输出不超过 76 个字符。此外,它以回车符 return 和换行符 (\r\n).
结尾
我有一个 base64 编码的字符串,在 php 中编码,现在我必须解码为 java 中的原始字符串。
第一次尝试用java.util.Base64.getDecoder().decode(encodedString)
解码。
但它抛出 Illegal base64 character 25
。
经过多次尝试,我用org.asynchttpclient.util.Base64.decode(encodedString)
但是,有什么区别呢?非常感谢!
根据文档:org.asynchttpclient.util.Base64
Implements the "base64" binary encoding scheme as defined by RFC 2045. Portions of code here are taken from Apache Pivot
所以它是多用途 Internet 邮件扩展 (MIME) 的实现 RFC 2045
根据文档:java.util.Base64.getDecoder()
Returns a Base64.Decoder that decodes using the Basic type base64 encoding scheme.
Basic
Uses "The Base64 Alphabet" as specified in Table 1 of RFC 4648 and RFC 2045 for encoding and decoding operation. The encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters outside the base64 alphabet.
java.util.Base64.getDecoder()
returns解码器根据RFC 4648。解码器拒绝包含 base64 字母表之外的字符的数据。它不是 MIME 实现。
要获得相同的行为,您需要使用 java.util.Base64.getMimeDecoder()
MIME
Uses the "The Base64 Alphabet" as specified in Table 1 of RFC 2045 for encoding and decoding operation. The encoded output must be represented in lines of no more than 76 characters each and uses a carriage return '\r' followed immediately by a linefeed '\n' as the line separator. No line separator is added to the end of the encoded output. All line separators or other characters not found in the base64 alphabet table are ignored in decoding operation.
MIME 编码器使用基本字母表生成 Base64 编码的输出。 每行输出不超过 76 个字符。此外,它以回车符 return 和换行符 (\r\n).
结尾