I have this php code which generate a HMAC (and not a simple message digest):
I use this for SHA 512 in Java. It might help:
public static String sha512 ( String str )
{
try
{
return sha512 ( str.getBytes ( "UTF-8" ) );
}
catch ( UnsupportedEncodingException e )
{
e.printStackTrace ( );
return "";
}
}
public static String sha512 ( byte[] array )
{
try
{
MessageDigest m = MessageDigest.getInstance ( "SHA-512" );
m.update ( array );
String hash = new BigInteger ( 1, m.digest ( ) ).toString ( 16 );
while ( hash.length ( ) < 32 )
{
hash = "0" + hash;
}
return hash;
}
catch ( NoSuchAlgorithmException e )
{
e.printStackTrace ( );
return "";
}
}
I also remember that there is detailed answer about MD-5 in a post in stackoverflow (just the algorythm is different)