String source = "admin";
//盐值
String salt = "123";
//散列次数
int hashIterations = 1;
第一种方法
Md5Hash md5Hash = new Md5Hash(source, salt, hashIterations);
String password_md5 = md5Hash.toString();
System.out.println("第一种:"+password_md5);
第二种
//第一个参数:散列算法
SimpleHash simpleHash = new SimpleHash("md5", source.getBytes("utf-8"), salt, hashIterations);
System.out.println(simpleHash.toString());
第三种
byte[] hashPassword = Digests.md5(new ByteArrayInputStream(source.getBytes("utf-8")));
System.out.println((Encodes.encodeHex(hashPassword)));
第四种
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(source.getBytes("utf-8"));
byte[] result = md.digest();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < result.length; i++) {
int val = result[i] & 0xff;
sb.append(Integer.toHexString(val));
}
System.out.println(sb.toString());