Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting MessageDigest to SHA-512 properly

843811Mar 17 2008 — edited Mar 2 2010
Hi everyone,

On PHP, getting hashes is very simple. Consider this code:
echo hash_hmac( "sha512", "abc", "def" );
Which outputs the sha512 hash of "abc" with salt "def", shows
17111e70f32d48a37ccc50a21deb12b40dfe223abf5ac852428000182125dab8a12ee95dd9f526bfb79c1a4fe00a4118e3b525f40eb8291325e3030f2e13ad34
I'm trying to replicate this behavior in Java, and thought I was on the right trail with:
String 			salt 	= "def";
MessageDigest 	md 		= MessageDigest.getInstance( "SHA-512" );
md.update( salt.getBytes( "UTF-8" ) );
byte [] data = md.digest( String.valueOf( "abc" ).getBytes( "UTF-8" ) );
System.out.println( data );
This however, only outputs trash ([B@190d11) instead of the expected digest. What am I doing wrong?

Thanks for the help.
Alex
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 30 2010
Added on Mar 17 2008
5 comments
528 views