Java8的java.util中新增了 Base64
Java
Base64.Encoder encoder = Base64.getEncoder();
String text = "測試中文";
byte[] textByte = text.getBytes("UTF-8");
String encoded_text = encoder.encodeToString(textByte);
Java
Base64.Decoder decoder = Base64.getDecoder();
String decoded_text = new String(decoder.decode(encoded_text), "UTF-8");