I'm trying to hash the same string in C# and in Java.
C# hash method:
public static string hashValue (string value)
{
byte[] input = null;
HashAlgorithm digest = HashAlgorithm.Create("SHA-512");
input = digest.ComputeHash(Encoding.UTF8.GetBytes(value));
return System.Text.UTF8Encoding.UTF8.GetString(input);
}
The output, in a WPF TextBox, for this is looking like: ""�?N[��"��2��D��j��t!z}7�H�p�J����GƼOp�EnBfHڄ�X���" .
The same function, in Java, is returning the result: "[B@41e2db20".
The Java hash method like this:
public static String hashValue(String value) {
byte[] input = null;
MessageDigest digest;
try {
digest = MessageDigest.getInstance("SHA-512");
try {
input = digest.digest(value.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} catch (NoSuchAlgorithmException e1) {
e1.printStackTrace();
}
return input.toString();
}
Can you please let me know what I'm doing wrong? Why is the result looking that weird in C#?