Base64加密解密
package com.nx.vip.p6.mesi;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import java.io.UnsupportedEncodingException;
public class MM {
//测试
public static void main(String[] args) {
String s= MM.setEncryptionBase64("123445666");
System.out.println("加密后的文本为:"+s);
String decodeBase64 = MM.getDecodeBase64(samples);
System.out.println("解密后的文本为:"+decodeBase64);
}
//加密
public static String setEncryptionBase64(String str){
byte[] b = null;
String s = null;
try {
b = str.getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if( b != null){
s = new BASE64Encoder().encode(b);
}
return s;
}
//解密
public static String getDecodeBase64(String str){
byte[] b = null;
String result = null;
if(str != null){
BASE64Decoder decoder = new BASE64Decoder();
try {
b = decoder.decodeBuffer(str);
result = new String(b, "utf-8");
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
}