• Base64加解密Java工具类Base64Util


    Base64加解密Java工具类

    import java.io.InputStream;
    import sun.misc.BASE64Decoder;
    import sun.misc.BASE64Encoder;
    
    /**
     * Base64加密与解密
     *
     * @author chenxy
     */
    @SuppressWarnings("restriction")
    public final class Base64Util {
    
    	/**
    	 * 解密
    	 *
    	 * @param is
    	 * @param charset
    	 * @return
    	 * @throws Exception
    	 */
    	public static String decode(InputStream is, String charset) throws Exception {
    		byte[] buffer = new BASE64Decoder().decodeBuffer(is);
    		return new String(buffer, charset);
    	}
    
    	/**
    	 * 解密
    	 *
    	 * @param content
    	 * @param charset
    	 * @return
    	 * @throws Exception
    	 */
    	public static String decode(String content, String charset) throws Exception {
    		byte[] buffer = new BASE64Decoder().decodeBuffer(content);
    		return new String(buffer, charset);
    	}
    
    	/**
    	 * 加密
    	 *
    	 * @param b
    	 * @return
    	 * @throws Exception
    	 */
    	public static String encode(byte[] b) throws Exception {
    		return new BASE64Encoder().encode(b);
    	}
    
    	/**
    	 * 加密
    	 *
    	 * @param content
    	 * @return
    	 * @throws Exception
    	 */
    	public static String encode(String content) throws Exception {
    		return encode(content.getBytes());
    	}
    
    	/**
    	 * 加密
    	 *
    	 * @param content
    	 * @param charset
    	 * @return
    	 * @throws Exception
    	 */
    	public static String encode(String content, String charset) throws Exception {
    		return encode(content.getBytes(charset));
    	}
    
    	private Base64Util() {
    	}
    
    }
    
  • 相关阅读:
    4/19学习总结
    人月神话读后感8
    4/18学习总结:PullToRefresh
    构建之法阅读笔记03
    构建之法阅读笔记02
    个人总结
    大二下学期课程总结
    学习进度16
    学习进度15
    课堂测试-找英语单词最长链
  • 原文地址:https://www.cnblogs.com/xusp/p/12735933.html
Copyright © 2020-2023  润新知