Can someone tell me what I'm doing wrong ? I'm trying to print SHA1 hash for "12345" but it displays the wrong one, I can't figure out what is the problem in the code
int main() {
string smth = "12345";
unsigned char hash[SHA_DIGEST_LENGTH];
SHA_CTX sha1;
SHA_Init(&sha1);
SHA_Update(&sha1, smth.c_str(), smth.length());
SHA_Final(hash, &sha1);
stringstream ss;
for (int i = 0; i < SHA_DIGEST_LENGTH; i++)
{
ss << hex << setw(2) << setfill('0') << (int)hash[i];
}
cout << ss.str() << endl; }
The hash I've got:
f7e507be49c187214406fd2556302ba47d535780
Correct hash:
8cb2237d0679ca88db6464eac60da96345513964
question from:
https://stackoverflow.com/questions/66057263/wrong-sha1-in-c-openssl 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…