In fact the toString(16) method will convert to hexadecimal so of 16. as you can see hash is a byte array and if you are to observe the Biginteger constructor the byte[] parameter is represented as: Binary representation of the magnitude of the number. You do not necessarily need to use the Biginteger class for such a task. A practical example for you to better understand the logic:
String message = "teste1234";
byte[] hash = MessageDigest.getInstance("MD5").digest(message.getBytes("UTF-8"));
char[] HEX_CHARS = "0123456789abcdef".toCharArray();
char[] chars = new char[2 * buf.length];
for (int i = 0; i < hash.length; ++i)
{
//Operadores bitwise para representar o valor do byte em hexadecimal
chars[2 * i] = HEX_CHARS[(buf[i] & 0xF0) >>> 4];
chars[2 * i + 1] = HEX_CHARS[buf[i] & 0x0F];
}
System.out.println("MD5: " + new String(chars));
In case the value is converted to "String" this is nothing more than the bitwise operators as shown above.
Hugs
Possible duplicate of Messagedigest and hash class with MD5 in java
– user28595
See the response of utluiz♦, in it, it explains exactly everything that is happening in this conversion.
– user28595
In fact, the vast majority of java classes have the method
toString()
, it is he who makes this conversion. Each class has its own implementation of this method.– user28595
@Diegof has some he doesn’t have?
– Maniero
@bigown so I replied as a comment, not sure if all has kkkk
– user28595