I started playing around with jython recently, and I was looking for an "easy" module to port to get to know it more. I found hashlib that, albeit from 2.5, should be pretty straightforward to implement on top of
java.security.MessageDigest. If i manage to complete the port, one could always keep it handy for a future release, right?
However, when doing a few tests with MessageDigest in Jython, I've encountered a little hurdle.
MessageDigest.digest() correctly returns an array of bytes; i can successfully encode these to hex and get a pretty hex string that is exactly the same as what python 2.5 returns with .hexdigest(). However, if I use the array to create a proper
java.lang.String, i get a slightly different result from what python returns with the digest() method.
There is something I'm missing about the internals of either Jython or Python... any ideas?
just to clarify...
---- in Python 2.5:
md5 = hashlib.new('MD5')
--- in jython 2.2a1:
from java.security import MessageDigest
md5 = MessageDigest.getInstance('MD5')
s1 = md5.digest()
# if i convert each chr to hex, it will correctly be
# so the 16 bytes are the same... however...
>>> pc5h:\x05\x05}\x148\xCA\xD6_\x1E\xBFP # notice the capital letters in the final parts
When outputting with print, the "weird" characters are exactly the same... so why the difference in capitalization?
I'm on Jython 2.2a1 on WinXPsp2, but i can test on Linux as well.