Java之Base64加密與解密


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); } }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM