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!

MessageDigest SHA-1 versus MySQL select sha1 (give different results)

843811Feb 13 2010 — edited Feb 13 2010
The first snippet is
         String password = "test1111";
         MessageDigest sha = MessageDigest.getInstance("SHA-1");
         sha.update(password.getBytes());
         return sha.digest();
The byte array returned is an array of 20 bytes with values
      byte[] = { -89, 67, -10, 0, 65, -120, -61, -124, -37, -11, 102, -64, -127, 28, -96, -55, 120, -32, 122, -101 };
On the other hand,
select sha1('test1111');
in the MySQL database results in
mysql> select sha1('test1111');
+------------------------------------------+
| sha1('test1111')                         |
+------------------------------------------+
| a743f6004188c384dbf566c0811ca0c978e07a9b |
+------------------------------------------+
1 row in set (0.00 sec)
Why are they different?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 13 2010
Added on Feb 13 2010
2 comments
277 views