File indexing completed on 2024-04-06 12:31:46
0001 #include <openssl/md5.h>
0002 #include <iostream>
0003 #include <iomanip>
0004 #include <sstream>
0005
0006 using namespace std;
0007 int main() {
0008 unsigned char hash[MD5_DIGEST_LENGTH];
0009 string data("foo-bar-bla");
0010 MD5((unsigned char*)data.c_str(), 11, hash);
0011 stringstream ss;
0012 for (unsigned int i = 0; i < MD5_DIGEST_LENGTH; i++) {
0013 ss << hex << setw(2) << setfill('0') << (int)hash[i];
0014 }
0015 string sha_result = "ad42a5e51344e880010799a7b7c612fc";
0016 string sha = ss.str();
0017 if (sha != sha_result) {
0018 cout << "Failed: SHA1 Mismatch:" << sha << " vs " << sha_result << endl;
0019 return 1;
0020 }
0021 cout << "Passed: SHA1 match:" << sha << " vs " << sha_result << endl;
0022 return 0;
0023 }