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;
}
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;
}
相关文章推荐
- Ceph RBD终端连接方案
- ADB and linux命令
- Android中自定义仿IOS回弹效果的ListView
- 屏幕适配相关知识点
- mysql学习——DATE_SUB()&EXTRACT() 函数
- 今天搞明白了内些传说中的硬件
- 各js取值。
- 免费的编程中文书籍索引
- PHP大神的十大优良习惯
- ASP.NET图片上传实例(附源码)
- MySQL提供的可以计算两个时间间隔的函数
- XML Publish开发--特殊字符转换
- 众数问题
- 当前进程(Linux Devices Driver)
- raid 0,1,10,5特性
- forward内部跳转 和redirect重定向跳转的区别
- windows文件上传到linux系统的文件内容问题
- Spring学习笔记
- WdfRequestRetrieveOutputBuffer
- require.js 入门学习-备