Create a gist now

Instantly share code, notes, and snippets.

How to calculate MD5 as zero-padded hex string in Groovy?
def digest = MessageDigest.getInstance("MD5")
def bytes = data.getBytes()
def md5 = digest.digest(bytes)
// Convert to hex, left-padded with 0 to 32 chars
def hex = new BigInteger(1, md5).toString(16).padLeft(32, "0")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment