1
I need to write a script using C++ and the OPENSSL library that takes this: 0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352
performs a SHA256 Hash using the sha256 function from the OpenSSL library and then returns 0b7c28c9b7290c98d7438e70b3d3f7c848fbd7d1dc194ff83f4f7cc9b1378e98 as the digest.
The issue I am having is that I get a different message digest after performing the sha256 hash function: a9ce83de3a0ff3516b7c50cdd787e9f69f152f227d93c9512774231e7132e925.
I've been stuck on this for about 2 weeks and from my research I have been told that my function is not doing the right conversion of my message before performing the Sha256 hash function.
Code
string sha256(const string str)
{
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, str.c_str(), str.size());
SHA256_Final(hash, &sha256);
stringstream ss;
for(int i = 0; i < SHA256_DIGEST_LENGTH; i++)
{
ss << hex << setw(2) << setfill('0') << (int)hash[i];
}
return ss.str();
}
int main()
{
cout << endl;
cout << sha256("0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352") << endl;
return 0;
}
could you specify to which 9 steps you are referring to? From a book or a guide somewhere online? – 0xb10c – 2018-07-04T16:31:31.703
here is a good cross reference page with the 9 steps: http://gobittest.appspot.com/Address - when you deal with hashings in bitcoin, you must make sure that you hash the hex data, not the (ASCII) strings. I don't know ow to do this in C++, I had the problem in my shell codings with openssl...
– pebwindkraft – 2018-07-04T21:17:56.200