Base64转码和解码的帮助类

 /**
     * 将字符串进行Base64编码
     *
     * @param s 被编码的字符串
     * @return 编码后的字符串
     */
    public static String encoderBASE64(String s) {
        if (s == null) {
            return null;
        }
        try {
            return Base64.encodeBase64String(s.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 将 BASE64 编码的字符串 s 进行解码
     *
     * @param s 被解码的字符串
     * @return 解码后的字符串
     */
    public static String decoderBASE64(String s) {
        String str = null;
        try {
            if (!StringUtils.isEmpty(s)) {
                byte[] b = Base64.decodeBase64(s);
                str = new String(b, "UTF-8");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return str;
    }

  

原文地址:https://www.cnblogs.com/baizhanshi/p/6835981.html