SHA-1, Java vs. openssl
843810Sep 26 2004 — edited Sep 28 2004Hi. 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.