MD5收集整理
MD5如何生成的
生成MD5
1.通过摘要生成MD5
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(input.getBytes(StandardCharsets.UTF_8));
byte[] hashBytes = md.digest();
StringBuilder sb = new StringBuilder();
for (byte b : hashBytes) {
sb.append(String.format("%02x", b));
}
return sb.toString();
2.使用Google的Guava生成MD5
- 添加依赖
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.1-jre</version>
</dependency>
- 生成代码
// com.google.common.hash.Hashing.md5()
// If you must interoperate with a system that requires MD5, then use this method, despite its deprecation. But if you can choose your hash function, avoid MD5, which is neither fast nor secure. As of January 2017, we suggest:
// For security: Hashing.sha256() or a higher-level API.
// For speed: Hashing.goodFastHash(int), though see its docs for caveats.
HashFunction hashFunction = Hashing.md5();
HashCode hash = hashFunction.hashString(input, StandardCharsets.UTF_8);
return hash.toString();
3.使用Appach的commons生成MD5
- 添加依赖
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.13</version>
</dependency>
- 生成代码
String md5 = DigestUtils.md5Hex( input );
return md5;
加盐MD5
作者:Ants_double
出处:https://www.cnblogs.com/ants_double/
本文版权归作者和博客园所有,欢迎转载。转载请在留言板处留言给我,且在文章标明原文链接,谢谢!
如果您觉得本篇博文对您有所收获,觉得我还算用心,请点击右下角的 [大拇指],谢谢!