java MD5

来源:互联网 发布:金扎医疗器械软件 编辑:程序博客网 时间:2024/05/17 22:43

// 将指定字符串经过MD5加密后返回 
<span style="font-family:Arial;background-color: rgb(255, 255, 255);">public static String encode(String pwd){    if(null == pwd){   return null;  }  String[] str = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};  StringBuilder sb = new StringBuilder();  MessageDigest digest;  try {   digest = MessageDigest.getInstance("MD5");  } catch (NoSuchAlgorithmException e) {   throw new RuntimeException(e);  }  byte[] b = digest.digest(pwd.getBytes());  for(byte single : b){   sb.append(str[(single >> 4) & 0x0f]); // 高四位   sb.append(str[single&0x0f]); // 低四位  }  return sb.toString(); }</span>


0 0
原创粉丝点击