package Demo_2_6_Base64加密與解密; import java.nio.charset.StandardCharsets; import java.util.Base64; public class Main { public static void main(String[] args) { /* Base64.Encoder:進行加密處理; - 加密處理:public byte[] encode(byte[] src); Base64.Decoder:進行解密處理。 - 解密處理: public byte[] decode(String src); * */ String msg = "www.mldn.cn"; // 需要加密的數據 String newMsg =new String(Base64.getEncoder().encode(msg.getBytes(StandardCharsets.UTF_8))); // 將數據轉換為byte類型 System.out.println(newMsg); String oldMsg = new String(Base64.getDecoder().decode(newMsg)); // 傳入需要解密的數據 System.out.println(oldMsg); } }