其他分享
首页 > 其他分享> > MD5收集整理

MD5收集整理

作者:互联网

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

标签:hash,收集整理,生成,MD5,input,md5,Hashing
来源: https://www.cnblogs.com/ants_double/p/11484432.html