Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Digest sha256 returns gibberish

by invalid_logic (Initiate)
on Aug 08, 2012 at 03:50 UTC ( #986131=note: print w/ replies, xml ) Need Help??


in reply to Re: Digest sha256 returns gibberish
in thread Digest sha256 returns gibberish

I'm hashing in order to verify pre-existing hash values that were generated with C++. The process and each steps results are documented but I'm following along in perl. So whatever the result I get, should match the authors examples.

The following is the concatenated result:

800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D

Which needs to match the following string after hashing with sha256*:

8147786C4D15106333BF278D71DADAF1079EF2D2440A4DDE37D747DED5403592

I've tried with sha256_base64 and it doesn't match.


Comment on Re^2: Digest sha256 returns gibberish
Select or Download Code
Replies are listed 'Best First'.
Re^3: Digest sha256 returns gibberish
by Athanasius (Abbot) on Aug 08, 2012 at 04:51 UTC
      This is what I'm following: https://en.bitcoin.it/wiki/Wallet_import_format

      The source code for the hex creation (see 'ToString') is here:

      https://github.com/bitcoin/bitcoin/blob/master/src/bignum.h

      As I'm just learning to program, I'm having trouble following the C++ code so instead trying to follow the wiki process. If they are concatenating the int(64) with something else, it's difficult for me to tell.

Re^3: Digest sha256 returns gibberish
by aitap (Deacon) on Aug 08, 2012 at 07:33 UTC
    You need to calculate sha256 on the binary form of this data, not on the hexademical string:
    $ perl '-MDigest::SHA "sha256_hex"' -E'say sha256_hex(pack("H*","800C2 +8FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D"))' 8147786c4d15106333bf278d71dadaf1079ef2d2440a4dde37d747ded5403592
    Sorry if my advice was wrong.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://986131]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2015-07-30 04:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls