Norway


I need to write a script using C++ and the OPENSSL library that takes this:
0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b22

performs a Hash using the function from the OpenSSL library and then returns 0b7c28c9b720c98d7438e70b3d3f7c848fbd7d1dc14ff83f4f7cc9b1378e98 as the digest.

The issue I am having is that I get a different message digest after performing the sha256 hash function:
a9ce83de3a0ff3516b7c50cdd787e9f69f152f227d93c95774231e7132e925

I’ve been 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;
}



Source link
Based Blockchain Network

LEAVE A REPLY

Please enter your comment!
Please enter your name here