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
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
airhacks.fm the podcast:
Stay in touch: airhacks.news.