ITeye博客

BASE64 编码和解码

semicolon · 2010-10-13 09:23 · java · 编程语言 · Markdown

本文参考转发于: http://www.zhuoda.org/elite/34479.html


public static String base64DecoderTool(final String str) throws SystemException{

		BASE64Decoder decoder = new BASE64Decoder();
		String returnStr = null;
		byte[] b;
		
		try {
			b = decoder.decodeBuffer(str);
			returnStr = new String(b , "gbk");
		} catch (Exception e) {
			System.out.println(e.getMessage());
			throw new SystemException("BASE64被解析的字符串不能是空!");
		} 		
		return returnStr;
	}


public static String formBASE64Tool(final String str) throws SystemException{
		if (str == null || str.trim().length() <= 0 ){
			throw new SystemException("BASE64所进行编码的字符串不能为空");
		}
			
		return (new sun.misc.BASE64Encoder()).encode( str.getBytes() ); 
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。