'What is the difference between java.util.Base64.getDecoder().decode and org.asynchttpclient.util.Base64.decode?

I have a base64 encoded string,is encoded in php,now I have to decode to raw string in java.

At the first time, I try to decode by java.util.Base64.getDecoder().decode(encodedString).

But it throws Illegal base64 character 25.

error message pic

After many attempts,I make it with org.asynchttpclient.util.Base64.decode(encodedString)

But, what's the difference ? thx so much!



Solution 1:[1]

According to documentation: org.asynchttpclient.util.Base64

Implements the "base64" binary encoding scheme as defined by RFC 2045. Portions of code here are taken from Apache Pivot

So it is the implementation of Multipurpose Internet Mail Extensions (MIME) RFC 2045

According to documentation: 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 decoder according to RFC 4648. Decoder rejects data that contains characters outside the base64 alphabet. It is not MIME implementation.

To have the same behavior you need to use 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.

The MIME encoder generates a Base64-encoded output using the basic alphabet. Each line of the output is no longer than 76 characters. Also, it ends with a carriage return followed by a linefeed (\r\n).

What is the difference between base64 and MIME base 64?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1