下载地址: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);
}
}