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 - Java™ Platform Standard Ed. 8 ... This class implements a decoder for decoding byte data using the Base64 encoding scheme as specified in RFC 4648 and RFC 2045.
🌐
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.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › net › URLDecoder.html
URLDecoder (Java Platform SE 8 )
July 21, 2026 - This class contains static methods for decoding a String from the application/x-www-form-urlencoded MIME format.
🌐
URL Decode
urldecoder.org › dec › java
URL Decoding of "java" - Online
Decode java from URL-encoded format with various advanced options. Our site has an easy to use online tool to convert your data.
🌐
GeeksforGeeks
geeksforgeeks.org › java › base64-java-encode-and-decode-a-string
Base64 Java Encode and Decode a String - GeeksforGeeks
July 23, 2025 - In Java, the java.util.Base64 class provides static methods to encode and decode between binary and base64 formats.
🌐
Base64.Guru
base64.guru › home › developers › java
Java Base64 Decode | Java | Developers | Base64
import java.util.Base64; class Base64Decode { public static void main(String[] args) { String b64 = "Z3VydQ=="; byte[] decoder = Base64.getDecoder().decode(b64); String str = new String(decoder); System.out.println(str); //-> "guru" } }
🌐
Decodejava
decodejava.com
Decodejava.com presenting simple and easy Java tutorials
Basic Java String File I/O Threads Applets Collections Events and AWT Swing & JDBC ... Welcome to Decodejava - An online portal that provides free and easy tutorials of Java programming language.
Find elsewhere
🌐
Educative
educative.io › answers › how-to-perform-base64-encoding-and-decoding-in-java
How to perform base64 encoding and decoding in Java
In Java 8, the Base64 class is added to the java.util package, which encodes the input with A-Za-z0-9+/ character set and decodes the encoded string.
🌐
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.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › byte_decode.htm
Java - Byte decode() Method
The Java Byte decode(String nm) method decodes a String into a Byte. Accepts decimal, hexadecimal, and octal numbers given by the following grammar − The sequence of characters following an optional sign and/or radix specifier ("0x", "0X", "#", or
🌐
Medium
medium.com › @behindjava.com › what-is-encoding-and-decoding-in-java-4c7269b3332
What is Encoding and Decoding in Java | by Chellalakshmideepak | Medium
July 6, 2022 - it provides convenient static utility method Base64.encodeBase64(byte[]) and Base64.decodeBase64(byte []) for converting binary data into base64 encoded binary Stream and than decoding back from encoded data in base64 encoding mechanism. Many times we need to encode sensitive data be it binary String format transferring over socket or transferring or storing data in xml files. Though there are other open source library available which provides support to encode any String into base64 e.g. MimeUtil from javax.mail package but Apache commons codec package is really handy and doesn’t add lot of extra stuff.
🌐
Base64 Decode and Encode
base64decode.net › java-decode
Java decode() - Base64 Decode
import java.util.Base64; import java.nio.charset.StandardCharsets; public class Base64Decode { public static void main(String[] args) { String encoded = "QmFzZTY0IERlY29kZQ=="; byte[] decoded = Base64.getDecoder().decode(encoded); String decodedStr = new String(decoded, StandardCharsets.UTF_8); System.out.println(decodedStr); } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-long-decode-method-with-examples
Java Long decode() method with Examples - GeeksforGeeks
December 5, 2018 - Number = 54534 Program 2: The program demonstrates the conversions using decode() function ... // Java program to demonstrate // of java.lang.Long.decode() method import java.lang.Math; class GFG { // driver code public static void main(String args[]) { // demonstration of conversions String decimal = "10"; // Decimal String hexa = "0XFF"; // Hexa String octal = "067"; // Octal // convert decimal val to number using decode() method Integer number = Integer.decode(decimal); System.out.println("Decimal [" + decimal + "] = " + number); number = Integer.decode(hexa); System.out.println("Hexa [" + hexa + "] = " + number); number = Integer.decode(octal); System.out.println("Octal [" + octal + "] = " + number); } } Output:
🌐
Java Decompilers
javadecompilers.com
Java decompiler online
Java decompilers online: *JAD, *JDCore, *Procyon, *Fernflower, *CFR. ✓ A user interface to extract source code from .class and .jar ‘binary’ files.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › nio › charset › CharsetDecoder.html
CharsetDecoder (Java Platform SE 8 )
July 21, 2026 - Each invocation of the decode method will decode as many bytes as possible from the input buffer, writing the resulting characters to the output buffer. The decode method returns when more input is required, when there is not enough room in the output buffer, or when a decoding error has occurred.
🌐
LabEx
labex.io › tutorials › java-java-integer-decode-method-117702
Decoding Integers in Java: Mastering the decode() Method | LabEx
The decode() method of the Java Integer class is used to decode a String to an Integer value. It can decode a decimal, hexadecimal, or octal string, and it returns the integer value of the Integer object which the String holds.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › net › URLDecoder.html
URLDecoder (Java Platform SE 7 )
This class contains static methods for decoding a String from the application/x-www-form-urlencoded MIME format.
🌐
Javatpoint
javatpoint.com › java-base64-encode-decode
Java Base64 Encode Decode - javatpoint
Java Base64 Encode Decode examples and topics on functional interface, anonymous class, lambda for list, lambda for comparable, default methods, method reference, java date and time, java nashorn, java optional, stream, filter etc.