importsun.misc.BASE64Decoder;
importsun.misc.BASE64Encoder;
importjava.io.IOException;
public classBase64Test {
public static voidmain(String[] args)throwsIOException {
//编码器(加密器)
BASE64Encoder encoder =newBASE64Encoder();
//解码器(解码器)
BASE64Decoderdecoder =newBASE64Decoder();
String str ="helloBase64.....";
//需先把字符串转换为字节数组
str = encoder.encode(str.getBytes("utf-8"));
System.out.println("加密后:"+str);
byte[] b = decoder.decodeBuffer(str);
//解密后得到的也是字节数组需转为字符串
String result =newString(b,"utf-8");
System.out.println("解密后:"+result);
}
}