`
hekuilove
  • 浏览: 156527 次
  • 性别: Icon_minigender_1
  • 来自: 魔都
社区版块
存档分类
最新评论

JAVA Base64

 
阅读更多

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;
	}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics