常用的MD5工具类
public class MD5Util {
public static String hashKeyForDisk(String key){
String cacheKey="";
try{
final MessageDigest digest = MessageDigest.getInstance("MD5");
digest.update(key.getBytes());
cacheKey = bytesToHexString(digest.digest());
}catch(Exception e){
e.printStackTrace();
cacheKey = String.valueOf(key.hashCode());
}
return cacheKey;
}
private static String bytesToHexString(byte[] bytes){
StringBuilder sb = new StringBuilder();
for(int i=0;i<bytes.length;i++){
String hex = Integer.toHexString(0XFF&bytes[i]);
if(hex.length()==1){
sb.append('0');
}
sb.append(hex);
}
return sb.toString();
}
}