Base64转String,String转Base64,可以作为Base64Utils

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/pmdream/article/details/81383484

转载请注明出处。

   public static String strConvertBase(String str) {
        if(null != str){
            Base64.Encoder encoder = Base64.getEncoder();
            return encoder.encodeToString(str.getBytes());
        }
        return null;
    }

    public static String baseConvertStr(String str) {
        if(null != str){
            Base64.Decoder decoder = Base64.getDecoder();
            try {
                return new String(decoder.decode(str.getBytes()), "GBK");
            } catch (UnsupportedEncodingException e) {
                return null;
            }
        }
        return null;
    }

猜你喜欢

转载自blog.csdn.net/pmdream/article/details/81383484