Decodex

Choose the right Java Base64 decoder for basic, URL or MIME input

Decode three representations of the bytes FB FF in JShell. Match the decoder to an API parameter, a standard field or a wrapped mail body.

Select a decoder from the sender’s format

java.util.Base64 supplies getDecoder(), getUrlDecoder() and getMimeDecoder(). The URL alphabet uses - and _ where the basic alphabet uses + and /. The MIME decoder accepts wrapped mail bodies and skips other characters outside its alphabet too.

Compare the byte arrays in JShell

Run the lines below in JShell. Standard +/8=, unpadded URL-safe -_8 and the wrapped MIME value all yield the same two bytes. The first output is true and the next is FB FF. Comparing through new String can obscure the distinction because these bytes are binary.

import java.util.Base64;
import java.util.Arrays;
byte[] plain = Base64.getDecoder().decode("+/8=");
byte[] url = Base64.getUrlDecoder().decode("-_8");
byte[] mail = Base64.getMimeDecoder().decode("+/\r\n8=");
System.out.println(Arrays.equals(plain, url) && Arrays.equals(url, mail));
System.out.printf("%02X %02X%n", plain[0], plain[1]);

Keep strict fields strict

For a single-line basic Base64 field, use the basic decoder so unexpected characters remain visible as failures. For email, use a MIME parser to isolate the body first. Alphabetic characters in a header also belong to the Base64 alphabet, so the MIME decoder cannot remove headers for you.

Open the text decoder

Related guides

References

More online tools

Convert images, test your keyboard, and use other handy tools in your browser.

Explore Altomono tools