??C++???MD5????,????????????????????????????????MD5????:
#include
#include
#include
std::string md5(const std::string& input) {
unsigned char digest[MD5_DIGEST_LENGTH];
MD5((const unsigned char*)input.c_str(), input.length(), digest);
char mdString[33];
for(int i = 0; i < 16; i++) {
sprintf(&mdString[i*2], "x", (unsigned int)digest[i]);
}
return mdString;
}
int main() {
std::string input = "Hello, World!";
std::string md5Result = md5(input);
std::cout << "MD5 of '" << input << "' is: " << md5Result << std::endl;
return 0;
}
????????,???OpenSSL???MD5???????????MD5????????????????md5
??,??????MD5????????main
???,????"Hello, World!"????MD5???
??????,?????OpenSSL?,?????????OpenSSL???????????????:
g++ -o md5_example md5_example.cpp -lssl -lcrypto
????????C++???MD5?????