以前用过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); } }
/**
*
* @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);
}
}