2 * @brief Util class implementation.
6 * @copyright Intra2net AG
13 #include <openssl/evp.h>
14 #include <openssl/md5.h>
25 * Computes a MD5 Digest from the given string and returns the HEX representation
26 * @param data The string to compute the md5 for
27 * @return The computed md5 in hex
29 std::string Util::compute_md5_digest(std::string data)
31 // compute an MD5 digest.
36 unsigned char md_value[EVP_MAX_MD_SIZE];
39 OpenSSL_add_all_digests();
41 md = EVP_get_digestbyname("md5");
43 EVP_MD_CTX_init(&mdctx);
44 EVP_DigestInit_ex(&mdctx, md, NULL);
45 EVP_DigestUpdate(&mdctx, data.c_str(), strlen(data.c_str()));
46 EVP_DigestFinal_ex(&mdctx, md_value, &md_len);
47 EVP_MD_CTX_cleanup(&mdctx);
51 for(int i = 0; i < md_len; i++)
53 sprintf(buffer,"%02x", md_value[i]);
54 result.append(buffer);