Base64 Encoding With JDK 1.6+ And Java 8

The method: javax.xml.bind.DatatypeConverter#printBase64Binary(byte[]) encodes a byte[] into a Base64 encoded string.

To encode a String with JDK 1.6+ use the static method printBase64Binary:

String encodedDuke = DatatypeConverter.printBase64Binary("duke".getBytes("UTF-8"));

Java 8 comes with the java.util.Base64 class entirely dedicated to Basic, URL, Filenames and MIMEs encoding and decoding.

See you at Java EE Workshops at MUC Airport!

Web Apps, SPA, PWA with vanilla Java Script (ES 6+), CSS 3 and WebStandards only. As simple as possible, but not simpler. See you at: (Progressive) Web apps, Single Page Apps and WebStandards airhacks workshops at MUC airport, Winter Edition the podcast:

Stay in touch:


It's time for Java 8 and JEE 7 :-)

Posted by gustav on August 24, 2013 at 02:58 PM CEST #

Hello Adam, thank you.
Few days ago before your post i removed Bouncy Castle provider from project which was used for converting data to base64 and back.
Also DatatypeConverter class contains many helpful methods not only for base64 coding/encoding.

Posted by Vitaliy Kalayda on August 25, 2013 at 01:49 AM CEST #

the link

is dead!

Posted by Hossein on March 25, 2015 at 07:10 PM CET #

I'm not a developer, i always use the free online base64 string converter( to encode and decode base64.

Posted by JonyGreen on September 23, 2015 at 04:51 AM CEST #

Great Link,
Here some usefull web site to base64 encode

Posted by avi g on October 12, 2015 at 03:25 PM CEST #

> is dead!


Posted by Adrian on December 20, 2018 at 01:33 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments