Standard Base64 encoding and decoding
Use java.util.Base64 instead of internal JDK classes or third-party codecs.
Code Comparison
✕ Internal JDK API
String encoded = new sun.misc.BASE64Encoder()
.encode(data);
✓ Java 8+
String encoded = Base64.getEncoder()
.encodeToString(data);
See a problem with this code? Let us know.
Why the modern way wins
Supported API
Avoids inaccessible sun.misc implementation classes.
Complete variants
Includes basic, URL-safe, and MIME encoders and decoders.
No dependency
Encoding and decoding are built into the JDK.
Old Approach
sun.misc encoder
Modern Approach
Standard Base64 API
Since JDK
8
Difficulty
Beginner
JDK Support
Standard Base64 encoding and decoding
Available
Widely available since JDK 8 (March 2014).
How it works
The standard Base64 API provides basic, URL-safe, and MIME encoders and decoders without relying on unsupported internal packages. Use getEncoder() and getDecoder() for standard Base64, or select the URL and MIME variants when the target format requires them.
Related Documentation
Proof