How can I generate an MD5 hash?

Total Post:20


 1348  View(s)
Rate this:
Is there any method to generate MD5 hash of a string in Java?
  1. Re: How can I generate an MD5 hash?

    There's an input stream decorator,, so that you can compute the digest while using the input stream as you normally would, instead of having to make an extra pass over the data.

    MessageDigest md = MessageDigest.getInstance("MD5");
    try (InputStream is = Files.newInputStream(Paths.get("file.txt"))) {
      DigestInputStream dis = new DigestInputStream(is, md);
      /* Read stream to EOF as normal... */
    byte[] digest = md.digest();

    Use DigestUtils from Apache Commons Codec library:
    FileInputStream fis = new FileInputStream(new File("foo"));
    String md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis);

      Modified On Apr-10-2018 12:59:01 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.