BASE64 编码和解码

本文参考转发于: 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() ); 
	}

你可能感兴趣的:(html,sun)