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     }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM