Wednesday, April 8, 2015

Convert a byte array to Hexadecimal string in Java

Use the DatatypeConverter liibrary that can be imported as:

>> import javax.xml.bind.DatatypeConverter;

And then lets say certificate.getSignature() is returning a byte array, use these commands:

>> byte[] sign = certificate.getSignature();
>> String hexasign = DatatypeConverter.printHexBinary(sign);
>> System.out.println("Signature on the Certificate: "+hexasign+"\n");