zoukankan      html  css  js  c++  java
  • 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() {
    	}
    
    }
    
  • 相关阅读:
    排序算法-Java实现
    Linux-文件内容的查阅
    Linux-文件权限概念
    Linux-awk和sort处理字符串
    面试题-总结(二)
    面试题-总结(一)
    程序员的其他技能:股票-ROE解释
    程序员的其他技能:基金初识-基金名称的秘密
    tp框架表单验证 及ajax
    tp框架做留言板
  • 原文地址:https://www.cnblogs.com/xusp/p/12735933.html
Copyright © 2011-2022 走看看