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("你好")));
}
}
Java实现Base64加密解密
最新推荐文章于 2024-07-31 17:31:16 发布