5
I am trying to generate an MD5 hash using the class MessageDigest
, however, I cannot correctly display the hash as a string on the screen. The result is a string of unknown characters.
Below is the test code:
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*
* @author
*/
public class TesteMD5
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
String str = "teste md5";
try{
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes());
byte[] bytes = md.digest();
System.out.println("Hash: " + new String(bytes));
}catch(NoSuchAlgorithmException e){
e.printStackTrace();
}
}
}
The result I’m having is:
Hash: ���9��p>n$�u �