1 public class Base64 {
2 public static byte[] deCode(String src)
3 {
4 if (src.length() < 2)
5 {
6 return new byte[0];
7 }
8 byte dest[] = new byte[src.length() / 2];
9 Arrays.fill(dest, (byte) 0);
10 int index = 0;
11 for (int ii = 0; ii < src.length() - 1; ii++)
12 {
13 String str = "#" + src.substring(ii, ii + 2);
14 byte rb = (byte) Integer.decode(str).intValue();
15 dest[index++] = rb;
16 ii++;
17 }
18
19 return dest;
20 }
21
22 public static String enCode(byte bsrc[])
23 {
24 String dest = "";
25 if (bsrc == null)
26 {
27 return "";
28 }
29 for (int ii = 0; ii < bsrc.length; ii++)
30 {
31 byte bb = bsrc[ii];
32 int num;
33 if (bb >= 0)
34 {
35 num = bb;
36 }
37 else
38 {
39 num = (bb & 0x7f) + 128;
40 }
41 String str = Integer.toHexString(num);
42 if (str.length() < 2)
43 {
44 str = "0" + str;
45 }
46 dest = dest + str.toUpperCase();
47 }
48
49 return dest;
50 }
51 }