1 29 package com.yworks.yguard.obf; 30 31 import java.io.*; 32 import java.util.*; 33 34 39 public class Tools 40 { 41 43 44 46 47 51 public static boolean isInArray(String s, String [] list) 52 { 53 for (int i = 0; i < list.length; i++) if (s.equals(list[i])) return true; 54 return false; 55 } 56 57 58 private static final char[] base64 = { 59 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 60 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 61 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 62 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}; 63 private static final char pad = '='; 64 public static String toBase64(byte[] b) 65 { 66 StringBuffer sb = new StringBuffer (); 67 for (int ptr = 0; ptr < b.length; ptr += 3) 68 { 69 sb.append(base64[(b[ptr] >> 2) & 0x3F]); 70 if (ptr + 1 < b.length) 71 { 72 sb.append(base64[((b[ptr] << 4) & 0x30) | ((b[ptr + 1] >> 4) & 0x0F)]); 73 if (ptr + 2 < b.length) 74 { 75 sb.append(base64[((b[ptr + 1] << 2) & 0x3C) | ((b[ptr + 2] >> 6) & 0x03)]); 76 sb.append(base64[b[ptr + 2] & 0x3F]); 77 } 78 else 79 { 80 sb.append(base64[(b[ptr + 1] << 2) & 0x3C]); 81 sb.append(pad); 82 } 83 } 84 else 85 { 86 sb.append(base64[((b[ptr] << 4) & 0x30)]); 87 sb.append(pad); 88 sb.append(pad); 89 } 90 } 91 return sb.toString(); 92 } 93 } 94 | Popular Tags |