日期:2014-05-20  浏览次数:20708 次

一个加密程序。无法解析 Base64
无法解析 Base64这个是什么意思啊。是要导入jar包吗。

------解决方案--------------------
org.apache.commons.codec.binary.Base64
------解决方案--------------------
sun.misc.BASE64Encoder
------解决方案--------------------
以前用过BouncyCastle,线面参考《Java 加解密艺术》

import org.bouncycastle.util.encoders.Base64;
/**
 * 
 * @author Administrator
 *
 */
public abstract class Base64Code {

public final static String ENCODEING = "UTF-8";
/**
 * 
 * @param data need base64 encode
 * @return the value of base64
 * @throws Exception
 */
public static String encode(String data)throws Exception{
byte[] b = Base64.encode(data.getBytes(ENCODEING));
return new String(b, ENCODEING);
}

/**
 * 
 * @param data
 * @return
 * @throws Exception
 */
public static String decode(String data)throws Exception{
byte[] b = Base64.decode(data.getBytes(ENCODEING));
return new String(b, ENCODEING);
}
}