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() {
    	}
    
    }
    
  • 相关阅读:
    RESTful
    Node.js Express 框架
    Node.js Web 模块
    Node.js Path 模块
    JavaFX输入并显示字符串
    JavaFX手眼协调小游戏(赋源代码)
    JavaFX作业七参考
    管理运筹学(Additional Simplex Algorithm)
    JavaFX15.4 ( 创建一个簡单的计算器 ) 编写一个程序完成加法、减法、乘法和除法操作
    JavaFX移动小球
  • 原文地址:https://www.cnblogs.com/xusp/p/12735933.html
Copyright © 2011-2022 走看看