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!

SHA-1, Java vs. openssl

843810Sep 26 2004 — edited Sep 28 2004
Hi. I have tried to use the MessageDigest class in Java to compute SHA1 of a String, but the result I get from using openssl in Linux is different.

In Java:
SHA1 of Jelani Nelson is:
3575feeb4c2fd2f5b5e0b18dae06159e289e73ad

but in Linux using: echo "Jelani Nelson" | openssl sha1, I get the following:
c14524c53c57b78b0ec1f789d72d382f5c938a72

This is the way I'm calling digest() in Java:

MessageDigest md = null;
try { md = MessageDigest.getInstance("SHA1"); }
catch(NoSuchAlgorithmException e) {}
String s = "Jelani Nelson";
byte[] result = md.digest(s.getBytes());

I've showed the hex for the array just to make it easily comparable to the Linux output.
Can someone tell me why these values are different? Thank you.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 26 2004
Added on Sep 26 2004
7 comments
805 views