1.使用jdk自带包解码编码:
package com.cl;
import java.io.IOException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class JdkBase64 {
private static String src="imooc security base64";
public static void main(String[] args) {
base64();
}
public static void base64(){
BASE64Encoder encoder=new BASE64Encoder();
String dst=encoder.encode(src.getBytes());
System.out.println("encode:"+dst);
BASE64Decoder decoder=new BASE64Decoder();
try {
System.out.println(new String(decoder.decodeBuffer(dst)));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
若遇到不能引入相关BASE64Decoder和BASE64Decoder包的话,可以用如下方法解决:
https://blog.csdn.net/erlian1992/article/details/79518416
2.使用Bouncy Caslte提供的包Base64解密加密:需要