The results of sha1 encryption are different between python and java
Question: An application, i need sha1 encryption,but the results are different between
python and java, java is correct. Because there is no byte object in python,
and java byte is used for hash calculation. How to get the correct results
with python?


Answer: As usual, the difference is **not** in the digest implementation (those are
well-documented and implemented correctly in all major libraries). The
difference is in how you _represent_ the resulting data.

`md.digest()` returns a `byte[]` with the binary data produced by the digest.

`new String(md.digest())` tries to interpret those bytes as text in the
platform default encoding which is _almost certainly_ not what you want.

You _probably_ want the digest to be represented in a hex- or Base64 encoding.

Try this (make sure to import
[`javax.xml.bind.DatatypeConverter`](http://download.oracle.com/javase/7/docs/api/javax/xml/bind/DatatypeConverter.html)):

    
    
    String result = DatatypeConverter.printHexBinary(md.digest());
    

Alternatively, if you need Base64, use `printBase65Binary()` instead.

