Base64加密和解密

 

Base64URLSafeString

 1     /**
 2      * 将内容进行Base64加密
 3      *
 4      * @param content
 5      * @return
 6      * @throws UnsupportedEncodingException
 7      */
 8     public static String Base64encodeBase64URLSafeString(String content) throws Exception {
 9         String base64Str = "";
10         try {
11             base64Str = Base64.encodeBase64URLSafeString(content.getBytes("UTF-8"));
12         } catch (Exception e) {
13             System.out.println(e.getMessage());
14         }
15         return base64Str;
16     }

BASE64加密

 1     /**
 2      * 普通Base64加密
 3      *
 4      * @param str
 5      * @return
 6      * @throws IOException
 7      */
 8     public static String BASE64Encoder(String str) throws IOException {
 9         BASE64Encoder encoder = new BASE64Encoder();
10         String encode = encoder.encode(str.getBytes("UTF-8"));//编码
11         return encode;
12     }

BASE64解密

 1     /**
 2      * 普通Base64解密
 3      *
 4      * @param str
 5      * @return
 6      * @throws IOException
 7      */
 8     public static String BASE64Decoder(String str) throws IOException {
 9         BASE64Decoder decoder = new BASE64Decoder();
10         String decode = new String(decoder.decodeBuffer(str), "UTF-8");
11         return decode;
12     }

 

posted @ 2022-02-17 09:38  勤快的懒羊羊  阅读(774)  评论(0编辑  收藏  举报