This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Just iterate over the byte array and convert each byte to 2 hex digits. You could use String.format, or Integer.toHexString(), though with the latter, you'd have to prefix values < 16 with a leading 0 yourself.
Joined: Feb 03, 2012
Thanks for the reply. I know how to code up a conversion but I was looking to see if there was a direct way either via MessageDigest or some built-in function.
Dennis Putnam wrote:Thanks for the reply. I know how to code up a conversion but I was looking to see if there was a direct way either via MessageDigest or some built-in function.
You can look through MD's methods to see if anything does it. If not (and I suspect it won't be there), other potential candidates might be String, Integer, and Byte, and java.util.Arrays.
And note that if one of them has it, it's not a "built-in function" in the language sense. It'll just be a method written in Java that happens to come bundled with the core API but that'd be no different from one you can write yourself.