//编码 String message = "我是码农"; String encode = base64.getEncoder().encodeToString(message.getBytes(StandardCharsets.UTF_8)); // 方式一 String encode2 = new String(base64.getEncoder().encode(message.getBytes()), StandardCharsets.UTF_8); // 方式二 System.out.println(encode); // 5oiR5piv56CB5Yac System.out.println(encode2); // 5oiR5piv56CB5Yac
//解码 String decode = new String(base64.getDecoder().decode(encode), StandardCharsets.UTF_8); System.out.println(decode); // 我是码农



