您的位置:首页 > 编程语言 > Java开发

Java实现Base64加密解密

2016-08-05 10:47 441 查看
import java.io.IOException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class Base64Util {
//加密方法
public static String encode(String plainText){
return new BASE64Encoder().encode(plainText.getBytes());
}
//解密方法
public static String decode(String cipherText) {
byte[] buffer;
try {
buffer =new BASE64Decoder().decodeBuffer(cipherText);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("密文有问题");
}
return new String(buffer);
}

public static void main(String[] args) {
System.out.println(encode("你好"));
System.out.println(decode(encode("你好")));

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: