0

I'm trying to implement the following steps in Python:

Compressed public key: 02F840A04114081690223B7069071A70D6DABB891763B638CC20C7EC3BD58E6C86 SHA-256 of public key yields: cb05d0fd5e76ba8ea88323fc5d3eefd09a78d8e2a5fd4955307b549657a31330 

This step is fairly simple, so I wrote this piece of code to see if it works as planned:

from binascii import hexlify from hashlib import sha256 master_key = hexlify("02F840A04114081690223B7069071A70D6DABB891763B638CC20C7EC3BD58E6C86") print(sha256(master_key).hexdigest()) 

However, this doesn't yield the expected result. Instead it gives me:

cee4b5650664b11623675d0371ab9dd1e3478758a95b189e54ecf8b7bdd7ba2d 

Using the string without hex-encoding it first doesn't yield the correct result either. Any ideas?

1
  • 1
    You're using hexlify() to convert the hex representation of the key to hex. It's already in hex. You probably want to use unhexlify(). Commented Jan 9, 2017 at 19:22

1 Answer 1

2

you want to unhexlify your hexadecimal representation:

from binascii import unhexlify from hashlib import sha256 master_key = unhexlify("02F840A04114081690223B7069071A70D6DABB891763B638CC20C7EC3BD58E6C86") print(sha256(master_key).hexdigest()) # cb05d0fd5e76ba8ea88323fc5d3eefd09a78d8e2a5fd4955307b549657a31330 
Sign up to request clarification or add additional context in comments.

2 Comments

That is what happens when you have no clue what hexadecimal actually looks like. Thank you! Is there any chance you were ever part of the ArmA 2 community?
the what?! and... no. sorry.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.