/ Published in: Groovy
Generating MD5 HEX string from either URL or File instance in Groovy (more elegant than the Java version).
Expand |
Embed | Plain Text
Comments
Subscribe to comments
You need to login to post a comment.
narkisr on 09/11/08
2 people have marked this snippet as a favorite
Generating MD5 HEX string from either URL or File instance in Groovy (more elegant than the Java version).
Subscribe to comments
You need to login to post a comment.
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