Author

Topic: different implementations of SHA256 (Read 877 times)

legendary
Activity: 4228
Merit: 1313
March 18, 2015, 10:10:36 AM
#4
I finally got the right output:
instead of doing:
Code:
// WRONG
string myString("800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D");
string myStringSHA = SHA256(myString)
I used:
Code:
// OK
string digest;
StringSource(myString, true, new HexDecoder(new StringSink(digest)));
string myStringSHA = SHA256(digest);
Thanks a lot Smiley

   


Exactly!  ;-)

It can be tricky.
member
Activity: 65
Merit: 16
March 18, 2015, 09:34:23 AM
#3
I finally got the right output:
instead of doing:
Code:
// WRONG
string myString("800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D");
string myStringSHA = SHA256(myString)
I used:
Code:
// OK
string digest;
StringSource(myString, true, new HexDecoder(new StringSink(digest)));
string myStringSHA = SHA256(digest);
Thanks a lot Smiley

   
legendary
Activity: 4228
Merit: 1313
March 17, 2015, 07:00:38 PM
#2
Are there different implementations of SHA256 ?

from the bx library:

>bx sha256 800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D
8147786c4d15106333bf278d71dadaf1079ef2d2440a4dde37d747ded5403592

from https://en.bitcoin.it/wiki/Wallet_import_format
sha256 (800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) =
8147786c4d15106333bf278d71dadaf1079ef2d2440a4dde37d747ded5403592

and

from c++ crypto++:
sha256(800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) =
E2E4146A36E9C455CF95A4F259F162C353CD419CC3FD0E69AE36D7D1B6CD2C09

from: http://www.xorbin.com/tools/sha256-hash-calculator
sha256(800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) =
e2e4146a36e9c455cf95a4f259f162c353cd419cc3fd0e69ae36d7d1b6cd2c09

The difference is in hashing the string (an ASCII representation of a hex number) instead of the actual hex number itself.

The wiki hashes the number, the calculator is hashing the string.
member
Activity: 65
Merit: 16
March 17, 2015, 02:10:13 PM
#1
Are there different implementations of SHA256 ?

from the bx library:

>bx sha256 800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D
8147786c4d15106333bf278d71dadaf1079ef2d2440a4dde37d747ded5403592

from https://en.bitcoin.it/wiki/Wallet_import_format
sha256 (800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) =
8147786c4d15106333bf278d71dadaf1079ef2d2440a4dde37d747ded5403592

and

from c++ crypto++:
sha256(800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) =
E2E4146A36E9C455CF95A4F259F162C353CD419CC3FD0E69AE36D7D1B6CD2C09

from: http://www.xorbin.com/tools/sha256-hash-calculator
sha256(800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D) =
e2e4146a36e9c455cf95a4f259f162c353cd419cc3fd0e69ae36d7d1b6cd2c09
Jump to: