text: Generating MD5 HEX string from either URL or File instance in Groovy (more elegant than the Java version).
  Expand | Embed | Plain Text
  -
  - MessageDigest digest = MessageDigest.getInstance("MD5")
  - file.withInputStream(){is->
  - digest.update(buffer, 0, read);
  - }
  - }
  - BigInteger bigInt = new BigInteger(1, md5sum)
  - }
  Report this snippet
  Tweet
  Thanks for the code sample! Found a small problem. To protect against leading zeros being dropped, change last line to.
  return bigInt.toString(16).padLeft(32, '0')
  Thanks for the comment, could you explain why 32 zero pad?
  This example would benefit from the line
  import java.security.MessageDigestto make it work on its own.
  Iv added the import, thanx for the comment.
  32 zero padding because the md5 digest string is expected to have 32 characters after left padding with zeros