package md5;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MakeMD5 {
public final static String getMD5(String str) {
char hexDiagitArr[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'a', 'b', 'c' };
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("MD5");// 创建md5算法摘要
digest.update(str.getBytes());// 更新摘要
byte mdBytes[] = digest.digest();// 加密并返回字节数组
char newCarr[] = new char[mdBytes.length * 2];
int k = 0;
for (int i = 0; i < mdBytes.length; i++) {
byte byte0 = mdBytes[i];
newCarr[k++] = hexDiagitArr[byte0 >>> 4 & 0xf];
newCarr[k++] = hexDiagitArr[byte0 & 0xf];
}
return String.valueOf(newCarr);
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}