zoukankan      html  css  js  c++  java
  • 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;
        }
    

      

  • 相关阅读:
    第五周
    第四周
    第三周作业
    第二周编程总结
    编程总结(3)
    编程总结(2)
    编程总结(1)
    第七周作业
    第六周作业
    第五周作业
  • 原文地址:https://www.cnblogs.com/baizhanshi/p/6835981.html
Copyright © 2011-2022 走看看