1 packagecn.easybuy.utils;2
3 importjava.security.InvalidKeyException;4 importjava.security.NoSuchAlgorithmException;5 importjava.text.SimpleDateFormat;6 importjava.util.Calendar;7 importjava.util.Date;8 importjava.util.Map;9 importjava.util.Random;10 importjava.util.UUID;11
12 importjavax.crypto.BadPaddingException;13 importjavax.crypto.Cipher;14 importjavax.crypto.IllegalBlockSizeException;15 importjavax.crypto.NoSuchPaddingException;16 importjavax.crypto.SecretKey;17 importjavax.crypto.spec.SecretKeySpec;18
19
20
21 public classStringUtils {22 private static String[] binaryArray =
23 {"0000","0001","0010","0011",24 "0100","0101","0110","0111",25 "1000","1001","1010","1011",26 "1100","1101","1110","1111"};27 //private static String[] chineseDigits = new String[] { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
28 public static String[] chineseDigits = new String[] { "零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};29
30 private static final char[] charBytes = { ‘0‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘8‘, ‘9‘,‘a‘, ‘b‘, ‘c‘, ‘d‘, ‘e‘, ‘f‘, ‘g‘, ‘h‘,31 ‘i‘,‘j‘,‘k‘,‘l‘,‘m‘,‘n‘,‘o‘,‘p‘,‘q‘,‘r‘,‘s‘,‘t‘,‘u‘,‘v‘,‘w‘,‘x‘,‘y‘,‘z‘};32
33 private static final char[] numberBytes = {‘0‘, ‘1‘, ‘2‘, ‘3‘, ‘4‘, ‘5‘, ‘6‘, ‘7‘, ‘8‘, ‘9‘};34
35 /**
36 * 生成指定位数的随机数子.37 *@paramnumber38 *@return
39 */
40 public static String randomNumbers(intnumber) {41 int count = 0; //生成的密码的长度
42 int i; //生成的随机数
43 final int maxNum =numberBytes.length;44 StringBuffer randomStr = new StringBuffer("");45 Random r = newRandom();46 while(count
48 i = Math.abs(r.nextInt(maxNum)); //生成的数最大为36-1
49 if (i >= 0 && i
57
58
59 public static String randomStrByNumber(intnumber) {60 int count = 0; //生成的密码的长度
61 int i; //生成的随机数
62 final int maxNum =charBytes.length;63 StringBuffer randomStr = new StringBuffer("");64 Random r = newRandom();65 while(count
67 i = Math.abs(r.nextInt(maxNum)); //生成的数最大为36-1
68 if (i >= 0 && i
76
77 public staticString randomUUID() {78 UUID uuid =UUID.randomUUID();79 return uuid.toString().replace("-", "").toUpperCase();80 }81 public static String digitsTochinese(inti){82 //大于10的需要重写
83 returnchineseDigits[i];84 }85 public staticString toAllUpperCase(String uuid) {86 StringBuffer buffer = newStringBuffer();87
88 for (int i = 0; i < uuid.length(); i++) {89 char c =uuid.charAt(i);90 if(Character.isLowerCase(c)) {91 buffer.append(Character.toUpperCase(c));92 } else{93 buffer.append(c);94 }95 }96 returnbuffer.toString();97 }98
99
100
101 //十六进制字符串转byte数组
102 public static byte[] hexStringToBytes(String hexStrin