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 @   勤快的懒羊羊  阅读(817)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示