MD加密算法

MD加密算法

//MD5加密算法
private static String md5(String string) {
   if (TextUtils.isEmpty(string)) {
       return "";
  }
   MessageDigest md5 = null;
   try {
       md5 = MessageDigest.getInstance("MD5");
       byte[] bytes = md5.digest(string.getBytes());
       StringBuilder result = new StringBuilder();
       for (byte b : bytes) {
           String temp = Integer.toHexString(b & 0xff);
           if (temp.length() == 1) {
               temp = "0" + temp;
          }
           result.append(temp);
      }
       return result.toString();
  } catch (NoSuchAlgorithmException e) {
       e.printStackTrace();
  }
   return "";
}
posted on 2021-11-29 21:58  jeremie_my00  阅读(213)  评论(0)    收藏  举报