Iterative hashing returns different values in Python and Java
问题 I'm trying to port a python (2.7) script to Java. It iterates a sha256 hash several times but they end up with different results. I've noticed the first time they return the same result, but from there on it differs. Here is the Python implementation: import hashlib def to_hex(s): print " ".join(hex(ord(i)) for i in s) d = hashlib.sha256() print "Entry:" r = chr(1) to_hex(r) for i in range(2): print "Loop", i d.update(r) r = d.digest() to_hex(r) And in Java: import java.security.MessageDigest