Chinaunix首页 | 论坛 | 博客
  • 博客访问: 26278832
  • 博文数量: 2065
  • 博客积分: 10377
  • 博客等级: 上将
  • 技术积分: 21525
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-04 17:50
文章分类

全部博文(2065)

文章存档

2012年(2)

2011年(19)

2010年(1160)

2009年(969)

2008年(153)

分类: Java

2010-06-06 12:49:01

package cn.test;
import sun.misc.BASE64Decoder;
public class Test {
 public static void main(String[] args) {
  System.out.println(getBASE64("fffdsd"));
  System.out.println(getFormBASE64("ZmZmZHNk"));
 }
 public static String getBASE64(String s) {
  if (s==null) return null;
  return (new sun.misc.BASE64Encoder()).encode(s.getBytes());
 }
 // 将BASE64编码的字符进行解码处理
 public static String  getFormBASE64(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;
  }
 }
}
阅读(709) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~