base64加、解密实现方法
// Base64加密算法
public static String base64Encode(String str) throws Exception {
String retStr = "";
try{
//BASE64加密算法
BASE64Encoder base64 = new BASE64Encoder();
byte[] xmlStr = str.getBytes();
retStr = base64.encode(xmlStr);
}catch(Exception e){
throw new RuntimeException("Base64编码 加密 失败!");
}
return retStr;
}
// Base64解码算法
public static String base64Decode(String str) throws Exception{
byte[] bt = null;
String retStr = "";
try{
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
bt = decoder.decodeBuffer(str);
retStr = new String(bt);
}catch(Exception e){
throw new RuntimeException("XML字符串Base64解码失败");
}
return retStr;
}
public static String base64Encode(String str) throws Exception {
String retStr = "";
try{
//BASE64加密算法
BASE64Encoder base64 = new BASE64Encoder();
byte[] xmlStr = str.getBytes();
retStr = base64.encode(xmlStr);
}catch(Exception e){
throw new RuntimeException("Base64编码 加密 失败!");
}
return retStr;
}
// Base64解码算法
public static String base64Decode(String str) throws Exception{
byte[] bt = null;
String retStr = "";
try{
sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
bt = decoder.decodeBuffer(str);
retStr = new String(bt);
}catch(Exception e){
throw new RuntimeException("XML字符串Base64解码失败");
}
return retStr;
}