MD5算法 判斷字符爲中文



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;
    }





發佈了66 篇原創文章 · 獲贊 30 · 訪問量 39萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章