MD5加密

public class MD5Util {

public static String getMD5str(String str){
MessageDigest md=null;
try {
md=MessageDigest.getInstance("MD5");
md.reset();
md.update(str.getBytes("utf-8"));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
byte[] bytes=md.digest();
StringBuffer md5buffer=new StringBuffer();

for(int i=0;i<bytes.length;i++){
if(Integer.toHexString(0xff & bytes[i]).length()==1){
md5buffer.append("0").append(Integer.toHexString(0xff & bytes[i]));
}else{
md5buffer.append(Integer.toHexString(0xff & bytes[i]));
}
}

return md5buffer.toString();
}

你可能感兴趣的:(md)