Base64加密解密实例
程序员文章站
2022-03-12 19:40:03
...
package testBase64;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class TestBase64 {
//加密
public static void encoder(String params){
String resqString = "";
BASE64Encoder encoder = new BASE64Encoder();
resqString = encoder.encode(params.getBytes());
resqString = "param=" + resqString;
System.out.println("param======="+resqString);
}
//解密
public static void decoder(String response){
byte[] respByte;
BASE64Decoder encoder = new BASE64Decoder();
try {
respByte = encoder.decodeBuffer(response);
String str = new String(respByte,"utf-8");
System.out.println("str======="+str);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args){
String param = "aaabbb";
//String response = "YWFhYmJi";
encoder(param);
//decoder(response);
}
}