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() {
    	}
    
    }
    
  • 相关阅读:
    JSON转JS对象,JS对象转JSON
    java 判断对象是否是某个类的类型两种方法
    关于多线程笔记
    Java 多线程编程
    javaScript正则表达式的使用
    java中正则表达式常用方法
    史上最全常用正则表达式大全
    正则表达式语法
    vue属性值调方法
    POJ-1562 Oil Deposits
  • 原文地址:https://www.cnblogs.com/xusp/p/12735933.html
Copyright © 2011-2022 走看看