BASE64加密/解密

 1 import java.io.IOException;
 2 import sun.misc.BASE64Decoder;
 3 import sun.misc.BASE64Encoder;
 4 
 5 public class Base64Util {
 6     private static BASE64Encoder BASE64Encoder = new BASE64Encoder();
 7 
 8     private static BASE64Decoder BASE64Decoder = new BASE64Decoder();
 9 
10     /* 加密 */
11     public static String encoder( byte[] bytes) {
12         return BASE64Encoder.encode(bytes);
13     }
14 
15     /* 解密 */
16     public static String decoder(String str) throws IOException {
17         byte[] decodeBuffer = BASE64Decoder.decodeBuffer(str);
18         return new String(decodeBuffer);
19     }
20 
21     public static byte[] decoderByByte(String str) throws IOException {
22         return BASE64Decoder.decodeBuffer(str);
23     }
24 
25 }
Author:Pale Life
From: 
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/live365wang/p/2732566.html