org.apache.commons.codec.binary.Base64


下載地址:http://commons.apache.org/proper/commons-codec/download_codec.cgi

鏈接:https://pan.baidu.com/s/1u2rJLGr-djqtO6aACCUIFQ
提取碼:qun6

鏈接:https://pan.baidu.com/s/10YZClBY7uGfiBOXu3BD3lQ
提取碼:5uyt

 

import org.apache.commons.codec.binary.Base64;

public class JdkBase64 {

public static void main(String[] args) {
String key = "這是需要加密的文字";
key = encode(key);
System.out.println(key);
key = decode(key);
System.out.println(key);
}

/**
* Base64加密
* @param key
* @return
*/
public static String encode(String key){
byte[] bt = key.getBytes();
return (new Base64().encodeToString(bt));
}

/**
* Baes64解密
* @param key
* @return
*/
private static String decode(String key){
byte[] bt = new Base64().decode(key);
return new String(bt);
}

}


免責聲明!

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



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