base64加、解密实现方法

// Base64加密算法    
    public static String base64Encode(String str) throws Exception {
        String retStr = "";
        try{
            //BASE64加密算法
            BASE64Encoder base64 = new BASE64Encoder();
            byte[] xmlStr = str.getBytes();
            retStr = base64.encode(xmlStr);
        }catch(Exception e){
            throw new RuntimeException("Base64编码 加密 失败!");
        }
        return retStr;
    }
 
    
     // Base64解码算法 
    public static String base64Decode(String str) throws Exception{
        byte[] bt = null;
        String retStr = "";
        try{
            sun.misc.BASE64Decoder decoder = new sun.misc.BASE64Decoder();
            bt = decoder.decodeBuffer(str);
            retStr = new String(bt);
        }catch(Exception e){
            throw new RuntimeException("XML字符串Base64解码失败");
        }
        return retStr;
    }
posted @ 2022-09-23 18:03  silentmuh  阅读(72)  评论(0编辑  收藏  举报
Live2D