import java.io.IOException;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class Base64 {
/**
*
* @param s
* @return<br>
* @date 2013年8月23日下午10:36:45<br>
*
*/
public static String encode(String s) {
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(s.getBytes());
}
public static String decode(String s) {
BASE64Decoder decoder = new BASE64Decoder();
try {
return new String(decoder.decodeBuffer(s));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static String decode(String s, String codeType) {
BASE64Decoder decoder = new BASE64Decoder();
try {
return new String(decoder.decodeBuffer(s), codeType);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
分享到:
评论