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() {
    	}
    
    }
    
  • 相关阅读:
    处理火星文重温vchar,char,nvchar,nchar
    删除文件
    js常用正则表达式
    安装iis 配置iis
    无题
    js函数大全
    常用正则表达式
    QQ在线客服
    获取系统文字字体
    无限级删除的存储过程
  • 原文地址:https://www.cnblogs.com/xusp/p/12735933.html
Copyright © 2011-2022 走看看