/**
*
*/
package com.wuhongbo.common.util.encry;
import java.io.IOException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
* Base64加密
*
* @author wuhongbo
*/
public class Base64Util
{
/**
* 加密
*
* @param bstr
* @return String
*/
public static String encode(String str)
{
if (str == null)
{
str = "";
}
return new BASE64Encoder().encode(str.getBytes());
}
/**
* 解密
*
* @param str
* @return string
*/
public static String decode(String str)
{
byte[] bt = null;
try
{
BASE64Decoder decoder = new BASE64Decoder();
bt = decoder.decodeBuffer(str);
}
catch (IOException e)
{
e.printStackTrace();
}
return new String(bt);
}
/**
* @param args
*/
public static void main(String[] args)
{
String s = "123abc中华人民共和国1111111111";
System.out.println("原码:" + s);
String s1 = encode(s);
System.out.println("编码:" + s1);
System.out.println("解码:" + decode(s1));
}
}