Java实现Base64加密解密

来源:互联网 发布:淘宝买家好评语大全50 编辑:程序博客网 时间:2024/05/14 03:37
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("你好")));}}

0 0