0

I am trying to understand how the crypto algorithms RIPEMD and SHA256 work. The bitcoin method for computing PKHash is RIPEMD160(SHA256(PublicKey)).

I am trying to first implement the RIPEMD of SHA256(PublicKey).

pkHashStep1=hashlib.sha256(public_key.decode('hex')).digest()
print 'MyTransaction pkHashStep1 {}'.format(pkHashStep1)

MyTransaction pkHashStep1 ▒▒▒so▒/▒▒e▒▒▒¡▒7▒?9▒▒.▒ӟ!n▒h

This outputs a string that I cannot use directly, but the hashlib library can use this. Trying pkHashStep1.decode('hex') and bin(pkHashStep1) throws an error. How does it convert the hash to a usable hexstring/bin??

Currently, I have publicKey as input to my RipeMD method, instead of the pkHashStep1, and have to separately do

input=hashlib.sha256(publicKey.decode('hex')).hexdigest()

FYI: I know there is a ripemd method in hashlib. Suggesting I use it is not an answer https://stackoverflow.com/a/2124289/4219479

Community
  • 1
  • 1
rrayas
  • 43
  • 8
  • If you're just asking how to convert a byte string to a hexadecimal string, see for example [this question](http://stackoverflow.com/questions/6624453/whats-the-correct-way-to-convert-bytes-to-a-hex-string-in-python-3). It was asked for Python 3 but also works for 2. – glibdud Feb 14 '17 at 15:39

1 Answers1

0

glibdud's comment got me to the answer.

hashlib.sha256(public_key.decode('hex')).digest().encode('hex')=
hashlib.sha256(public_key.decode('hex')).hexdigest()
rrayas
  • 43
  • 8