Base64 have many static encode methods returning byte[] as
Base64.encodeBase64(stringToEncode.getBytes(StandardCharsets.UTF_8.name()));
Also MessageDigest using static getInstance
to encode/digest
But Hex doesn't, it have only instance method encode which requires to create an instance
new Hex().encode(stringToEncode.getBytes(StandardCharsets.UTF_8.name()));
Is there a reason I need to create instance to get byte array or is there a better way?
I currently don't think adding getBytes()
is a good idea, for example
Hex.encodeHexString(stringToEncode).getBytes()