import java.io.UnsupportedEncodingException; import java.util.Base64; public class Base64Test { public static void main(String[] args) throws UnsupportedEncodingException { final String value = "test"; final byte[] encodedValue = Base64.getEncoder().encode(value.getBytes("UTF-8")); final byte[] decodedValue = Base64.getDecoder().decode(encodedValue); // should print 'test'! System.out.println(new String(decodedValue, "UTF-8")); } }