~~~
public String MD5(String string) {
MessageDigest md5 = null;
try {
md5 = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
md5.update(string.getBytes());
byte[] bytes = md5.digest();
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < bytes.length; i++) {
if (Integer.toHexString(0xff & bytes[i]).length() == 1) {
stringBuffer.append('0').append(Integer.toHexString(0xff & bytes[i]));
} else {
stringBuffer.append(Integer.toHexString(0xff & bytes[i]));
}
}
return stringBuffer.toString();
}
~~~