python - Sha256 returning incorrect hash values? -
i'm trying hash bitcoin private key checksum, , 2 different libraries in python (hashlib + pycrypto) returning same incorrect result (after 1 hash).
in linux terminal, correct hash result line:
echo -n 8018ac3e7343f016890c510e93f935261169d9e3f565436429830faf0934f4f8e4 | xxd -r -p | sha256sum -b result: cd358f378809b3043ded3782d849fbad70f92a2dadefafd985d9aef443752e57
however, hashlib, pycrypto, , online sha2 hash tool return value:
5d6dce0f36a50abe51ee435ac11dac05f7879c1cd1ca5bc7aae706e5a3776d4a
i'm not sure why returning different values.
here 2 wif-keys generated them, top 1 using command line function, second using python; second 1 invalid (not accepted wallet softwares).
5j19pgytjzus7voaqjxdjuggwxsnqj18gwswvfvqjzqqgtxzf2v 5j19pgytjzus7voaqjxdjuggwxsnqj18gwswvfvqjzqqgvdc8hm
import hashlib print( hashlib.sha256("8018ac3e7343f016890c510e93f935261169d9e3f565436429830faf0934f4f8e4").hexdigest() ) print( hashlib.sha256("8018ac3e7343f016890c510e93f935261169d9e3f565436429830faf0934f4f8e4".decode("hex")).hexdigest() )
notice difference:
the first code hashes hex string.
the second hashes byte string wich returned hex decode.
Comments
Post a Comment