[Building Sakai] sha1 in openssl and java

Jon Gorrono jpgorrono at ucdavis.edu
Thu Mar 12 17:34:31 PDT 2009


making this sakai-relevant:

currently 3akai is saving users-spaces in a jcr folder named in this
manner:  /_private/{SHA1-0}/{SHA1-1}/{userid}

... where {SHA1-0} is the first char of sha1 hash of {userid}
and {SHA1-1} is the second char of sha1 hash of {userid}

it would be nice for admin-types and forensic-ists to be able to know
where a particular userid is stored without using java.... so

Does anyone here know of a way to get the output from this java code :

          md = MessageDigest.getInstance("SHA-1");
          byte[] sha1hash = new byte[40];
          md.update("foo".getBytes(), 0, "foo".length());
          sha1hash = md.digest();
          System.out.println(new String(Hex.encodeHex(sha1hash)));

to match the output from this shell command:

echo "foo" | openssl dgst -sha1
... or have an altogether diff approach?


I suspect this is an charset encoding thing (eg,
"foo".getbytes(charSetName) ), but I have iterated thru all the
default java charsets to try to match the shell output (which is
US_en.UTF8) and cannot.

I have yet to try the reverse: to iterate thru all the iconv char sets
to try to match java output (this assumes that US_en.UTF8 matches one
of the iconv charsets)



-- 
Jon Gorrono
email{>+++++++++[>+++++++++++>++++++++++++>+++++++>+++++<<<<-]>+++++++.>++++.<---.>-.+++..---.-.+.>+.<++++++.<----.+.---.>+.<++++++++.>---.>>+.<<<----.-.>++.}
http{ats.ucdavis.edu}


More information about the sakai-dev mailing list