As of Java 8, there is an officially supported API for Base64 encoding and decoding. In time this will probably become the default choice.

The API includes the class java.util.Base64 and its nested classes. It supports three different flavors: basic, URL safe, and MIME.

Sample code using the "basic" encoding:

import java.util.Base64;

byte[] bytes = "Hello, World!".getBytes("UTF-8");
String encoded = Base64.getEncoder().encodeToString(bytes);
byte[] decoded = Base64.getDecoder().decode(encoded);
String decodedStr = new String(decoded, StandardCharsets.UTF_8);

The documentation for java.util.Base64 includes several more methods for configuring encoders and decoders, and for using different classes as inputs and outputs (byte arrays, strings, ByteBuffers, java.io streams).

Answer from Andrea on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Base64.Decoder.html
Base64.Decoder (Java Platform SE 8 )
July 21, 2026 - Returns an input stream for decoding Base64 encoded byte stream. The read methods of the returned InputStream will throw IOException when reading bytes that cannot be decoded. Closing the returned input stream will close the underlying input stream. ... Java™ Platform Standard Ed.
🌐
Baeldung
baeldung.com › home › java › java base64 encoding and decoding
Java Base64 Encoding and Decoding | Baeldung
February 18, 2026 - Java supports Base64 encoding and decoding features through the java.util.Base64 utility class.
🌐
Medium
medium.com › @rkgupta1298 › base64-encoding-in-java-7ff71ea0cc65
Base64 Encoding and Decoding in JAVA | by coffeebytes | Medium
March 15, 2022 - Base64 encoding and decoding capabilities were added in java8 via the java.util.Base64 utility class.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.base › java › util › Base64.html
Base64 (Java SE 11 & JDK 11 )
January 20, 2026 - Uses "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.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.util.base64.decoder.decode
Base64.Decoder.Decode Method (Java.Util) | Microsoft Learn
Decodes all bytes from the input byte buffer using the Base64 encoding scheme, writing the results into a newly-allocated ByteBuffer.
Find elsewhere
🌐
Apache Commons
commons.apache.org › proper › commons-net › jacoco › org.apache.commons.net.util › Base64.java.html
Base64.java
* * @param binaryData binary data to encode * @return String containing Base64 characters * @since 1.4 */ public static String encodeBase64URLSafeString(final byte[] binaryData) { return getUrlEncoder().withoutPadding().encodeToString(binaryData); } /** * Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature * * @param bigInt a BigInteger * @return A byte array containing base64 character data * @throws NullPointerException if null is passed in * @since 1.4 */ public static byte[] encodeInteger(final BigInteger bigInt) { return encodeBase64(toIntegerBytes(bigInt), false); } private static Decoder getDecoder() { return java.util.Base64.getDecoder(); } /** * Pre-calculates the amount of space needed to base64-encode the supplied array.
🌐
Android Developers
developer.android.com › api reference › base64
Base64 | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
InfoWorld
infoworld.com › home › software development › programming languages › java
Base64 encoding and decoding in Java 8 | InfoWorld
December 6, 2017 - By replacing + with - and / with _, URL and Filename Safe obviates the need for URL encoders/decoders (and their impacts on the lengths of encoded values). Also, this variant is useful when the encoded data is to be used for a filename because Unix and Windows filenames cannot contain /. Java 8 introduced a Base64 API consisting of the java.util.Base64 class along with its Encoder and Decoder nested static classes.
🌐
Base64 Decode
base64decode.org
Base64 Decode and Encode - Online
Please wait until the decoding process is complete. ... Please note that this file is removed from our system immediately after the first download attempt or 15 minutes of inactivity. ... Need this tool again? Bookmark this page for instant access next time. Meet Base64 Decode and Encode, a simple online tool that does exactly what it says: decodes from Base64 encoding as well as encodes into it quickly and easily.
🌐
GitHub
github.com › AdoptOpenJDK › openjdk-jdk11 › blob › master › src › java.base › share › classes › java › util › Base64.java
openjdk-jdk11/src/java.base/share/classes/java/util/Base64.java at master · AdoptOpenJDK/openjdk-jdk11
import java.nio.charset.StandardCharsets; import jdk.internal.HotSpotIntrinsicCandidate; · /** * This class consists exclusively of static methods for obtaining · * encoders and decoders for the Base64 encoding scheme. The · * implementation of this class supports the following types of Base64 ·
Author: AdoptOpenJDK
🌐
Apache Commons
commons.apache.org › proper › commons-codec › apidocs › org › apache › commons › codec › binary › Base64.html
Base64 (Apache Commons Codec 1.22.1 API)
Use builder() and Base64.Builder. All MethodsStatic MethodsInstance MethodsConcrete MethodsDeprecated Methods ... Creates a new Builder. ... Decodes Base64 data into octets.
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › util › Base64.Decoder.html
Base64.Decoder (Java SE 21 & JDK 21)
January 20, 2026 - It is the responsibility of the invoker of this method to make sure the output byte array dst has enough space for decoding all bytes from the input byte array. No bytes will be written to the output byte array if the output byte array is not big enough. If the input byte array is not in valid Base64 encoding scheme then some bytes may have been written to the output byte array before IllegalargumentException is thrown.
🌐
IBM
ibm.com › docs › en › samfess › 8.2.0
Base64.java file
The page you requested cannot be displayed (HTTP response code 403)
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.util.base64.decoder
Base64.Decoder Class (Java.Util) | Microsoft Learn
This class implements a decoder for decoding byte data using the Base64 encoding scheme as specified in RFC 4648 and RFC 2045.
🌐
DEV Community
dev.to › tooldeck › base64-decode-in-java-getdecoder-geturldecoder-getmimedecoder-and-streaming-3b9o
Base64 Decode in Java: getDecoder, getUrlDecoder, getMimeDecoder, and Streaming - DEV Community
April 9, 2026 - The basic decoder rejects anything outside the Base64 alphabet — and that includes the \r\n line breaks that MIME-encoded content always contains. Email attachments, PEM certificates, and some older API responses wrap Base64 output at 76 ...
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › util › Base64.html
Base64 (Java SE 17 & JDK 17)
April 21, 2026 - A Base64 decoder. ... Returns a Base64.Decoder that decodes using the MIME type base64 decoding scheme.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java 8 Base64 Encoding and Decoding (With Examples) - Java Code Geeks
September 8, 2020 - In java 8, We can use mainly 3 types of encoding and decoding capabilities as standard. All of the classes are related to this are in java.util.base64 package.