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 }