You need to convert the input string to a binary string using a hexdecoder. 
Something like

string decoded;

CryptoPP::StringSource(src, true, 
    new CryptoPP::HexDecoder(
    new CryptoPP::StringSink(decoded)));

Now use decoded instead of myString.


On Tuesday, March 17, 2015 at 2:44:18 PM UTC-7, JF Jobidon wrote:

> Hi
> I use c++ with crypto++ to generate a sha256 hash from this string:
> "800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D"
> I have the same result as
> http://www.xorbin.com/tools/sha256-hash-calculator :
>
> E2E4146A36E9C455CF95A4F259F162C353CD419CC3FD0E69AE36D7D1B6CD2C09
>
> but the problem is I try to obtain a private key for the Bitcoin protocol:
>
> when I use the *Bitcoin* Explorer (*bx*) command line tool.
>
> I have a different result:
>
> > bx sha256  
> 800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D
> 8147786c4d15106333bf278d71dadaf1079ef2d2440a4dde37d747ded5403592
>
> So I don't end up with the same private key (WIF)
>
> Question: are there different implementations of sha256?
>
> Thanks
> JF
>
>
> Here is my code using crypto++
>
> #include <cryptopp/hex.h>
> #include <cryptopp/sha.h>
> #include <cryptopp/base64.h>
> #include <iostream>
> #include <string>
>
> using namespace std;
>
> string makeSHA256 (const string);
>
> int main()
> {   
>     string myString = 
> "800C28FCA386C7A227600B2FE50B7CAE11EC86D3BF1FBE471BE89827E19D72AA1D";
>     
>    cout << makeSHA256(myString) << endl;        // 
> E2E4146A36E9C455CF95A4F259F162C353CD419CC3FD0E69AE36D7D1B6CD2C09
>     
>     return 0;
> }
>
>
> string makeSHA256 (const string myString) {
>     
>     string output;
>     
>     CryptoPP::SHA256 hash;
>     byte digest[CryptoPP::SHA256::DIGESTSIZE];
>
>     hash.CalculateDigest(digest,(const byte 
> *)myString.c_str(),myString.size());
>     //hash.CalculateDigest( digest, reinterpret_cast<byte*>(&myString[0]), 
> myString.length() );
>
>     CryptoPP::HexEncoder encoder;
>     CryptoPP::StringSink *SS = new CryptoPP::StringSink(output);
>     encoder.Attach(SS);
>     encoder.Put(digest,sizeof(digest));
>     encoder.MessageEnd();
>     
>     return output;
> }
>
>
>
>

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to