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!

different hash in java and mysql?

843811May 15 2005 — edited May 15 2005
i tried to do some password validation using sha digest in mysql database.
however, hash generated with my java code and mysql function is completely different.

mysql:
select  sha('a');
86f7e437faa5a7fce15d1ddcb9eaeaea377667b8
java
MessageDigest dg=MessageDigest.getInstance("SHA-256");
byte[] b=dg.digest("a".getBytes("ISO8859_1"));
System.out.println(Arrays.toString(b));
[-54, -105, -127, 18, -54, 27, -67, -54, -6, -62, 49, -77, -102, 35, -36, 77, -89, -122, -17, -8, 20, 124, 78, 114, -71, -128, 119, -123, -81, -18, 72, -69]
these bytes are nowhere near bytes i get from mysql, how am i supposed to interpret them?
mysql char set is set to latin1, that's why i used ISO8859_1? maybe i should use some other char set when converting bytes to unicode string?

thank you!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 12 2005
Added on May 15 2005
2 comments
268 views