public class CiferUtil {
private static final char[] HEX_0X = { '0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
public static String ciferByMD5(final String source) {
try {
// 利用MessageDigest类得到加密结果16个字节
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(source.getBytes());
byte[] bytes = md.digest();
String result = "";
// 把16个字节转换成16进制数
for (byte b : bytes) {
// 取字节高4位转换
result += HEX_0X[b >>> 4 & 0xf];
// 取字节低4位转换
result += HEX_0X[b & 0xf];
}
return result;
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
System.out.println(CiferUtil.ciferByMD5("abc4324"));
}
}