String result = String.format("%0" + messageDigest.length + "s", hexString.toString())
That's the shortest solution given what you already have. If you could convert the byte array to a numeric value, String.format
can convert it to a hex string at the same time.