您的位置:首页 > 其它

base64加、解密实现方法

2015-11-16 14:47 656 查看
// 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;

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