`
lcwyiyun
  • 浏览: 11425 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

java Base64 编码解码

阅读更多
	/**
	 * 编码
	 * @param input
	 * @return
	 */
	
	public static byte[] encode(byte[] input) {
		byte[] b = null;
		try {
			if (input != null && input.length > 0) {
				BASE64Encoder base64 = new BASE64Encoder();
				b = base64.encodeBuffer(input).trim().getBytes();
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return b;

	}
	
	/**
	 * 解码
	 * @param input
	 * @return
	 */
	public static byte[] decode(byte[] input) {
		try {
			if (input != null && input.length > 0) {
				BASE64Decoder bd = new BASE64Decoder();
				ByteArrayInputStream bis = new ByteArrayInputStream(input);
				input = bd.decodeBuffer(bis);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return input;
	}
分享到:
评论
发表评论

文章已被作者锁定,不允许评论。

相关推荐

Global site tag (gtag.js) - Google Analytics