How to Convert and Print Byte array to Hex String in Java

We often needs to convert byte arrays to Hex String in Java, In order to print byte array contents in readable format. Since many cryptographic algorithm e.g. MD5 return hash value as byte array, In order to see and compare those byte array, you need to convert byte array to Hex String. As we have seen, while generating MD5 check sum of File, there are multiple ways to convert byte array to Hexadecimal String in Java. You can either write your own method, or you can use open source library e.g. Apache commons codec to create Hex String from byte array in Java. Commons codec provides a utility class Hex, which contains a encodeHexString() method to create Hex String from byte array. It's one of the best option to generate Hex String, if you are already using this library to generate MD5 hash values. In this Java tutorial we will see what is issue with printing byte array as normal String, and 2 examples to convert byte array into Hexadecimal String in Java.
Read more »

0 Response to "How to Convert and Print Byte array to Hex String in Java"

Posting Komentar