使用BASE64编码解码
2015-10-30 11:24
477 查看
之前不知道base64 网上看了些资料 将可以使用的代码转了过来 作为总结
<span style="white-space:pre"> </span>import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
// 将 s 进行 BASE64 编码
public static String getBASE64(String s) {
if (s == null) return null;
return (new sun.misc.BASE64Encoder()).encode( s.getBytes() );
}
// 将 BASE64 编码的字符串 s 进行解码
public static String getFromBASE64(String s) {
if (s == null) return null;
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b);
} catch (Exception e) {
return null;
}
}
<span style="white-space:pre"> </span>import sun.misc.BASE64Encoder;
import sun.misc.BASE64Decoder;
// 将 s 进行 BASE64 编码
public static String getBASE64(String s) {
if (s == null) return null;
return (new sun.misc.BASE64Encoder()).encode( s.getBytes() );
}
// 将 BASE64 编码的字符串 s 进行解码
public static String getFromBASE64(String s) {
if (s == null) return null;
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b);
} catch (Exception e) {
return null;
}
}
相关文章推荐
- Quartz任务调度基本使用
- C语言跳表(skiplist)实现
- MariaDB通用二进制部署手册
- GCD - 1
- artdialog4.1.7 中父页面给子页面传值
- mysql-普通查询(General Query)慢查询(Slow Query)相关日志配置
- Web开发 Git和npm的安装
- Error:Could not read cache value from '/Users/wangjin/.gradle/daemon/2.2.1/registry.bin'.
- 哈希函数
- AsyncTask 轻入门
- Lua篇(第04章):来点高难度的,获取Lua表结构数据
- MessageQueue, Looper, Thread, Handler, Message, Messenger
- 计算机语言
- 太多太多杂事,什么时候能够安安静静的读本书,写篇技术博客
- SkipList跳表基本原理
- 线性判别分析LDA
- java.exe重命名之后无法被 jvisualvm、jconsole监控的问题
- linux内核注意事项
- java lock condition
- java基础学习笔记(2)