MD5算法:
public static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; public static String getMD5(String text) { String digest = ""; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(text.getBytes("utf-8")); byte b[] = md.digest(); char str[] = new char[b.length * 2]; int k = 0; for (int i = 0; i < b.length; i++) { byte byte0 = b[i]; str[k++] = HEX_DIGITS[byte0 >>> LENGHT_4 & BYTEMASK_HIGH]; str[k++] = HEX_DIGITS[byte0 & BYTEMASK_HIGH]; } digest = new String(str); } catch (NoSuchAlgorithmException e) { } catch (UnsupportedEncodingException e) { } return digest; }
public static boolean isChinese(String text) { boolean isChinese = false; if (!TextUtils.isEmpty(text)) { isChinese = true; int length = text.length(); for (int i = 0; i < length; i++) { char c = text.charAt(i); if (c < '\u4e00' || c > '\u9fa5') { isChinese = false; break; } } } return isChinese; }