16 #include "pol_global_config.h" 27 static HCRYPTPROV hProv = NULL;
29 bool MD5_Encrypt(
const std::string& in, std::string& out )
35 HCRYPTHASH hHash = NULL;
39 if ( !CryptAcquireContext( &hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT ) )
41 if ( !CryptAcquireContext( &hProv, NULL, NULL, PROV_RSA_FULL, 0 ) )
43 ERROR_PRINT <<
"Error " << GetLastError() <<
" acquiring crypt context\n";
49 if ( !CryptCreateHash( hProv, CALG_MD5, 0, 0, &hHash ) )
51 ERROR_PRINT <<
"Error " << GetLastError() <<
" creating hash\n";
56 if ( !CryptHashData( hHash, (
const unsigned char*)( in.data() ),
57 static_cast<unsigned long>( in.length() ), 0 ) )
59 ERROR_PRINT <<
"Error " << GetLastError() <<
" adding data to hash\n";
62 unsigned long len = 16;
63 unsigned char buf[16];
64 if ( !CryptGetHashParam( hHash, HP_HASHVAL, buf, &len, 0 ) )
66 ERROR_PRINT <<
"Error " << GetLastError() <<
" getting hash value\n";
70 std::ostringstream os;
71 for (
unsigned int i = 0; i < len; i++ )
73 os << std::setfill(
'0' ) << std::setw( 2 ) << std::hex << (int)buf[i];
77 CryptDestroyHash( hHash );
85 CryptReleaseContext( hProv, 0 );
91 #include <openssl/md5.h> 99 unsigned char sum[16];
101 MD5( reinterpret_cast<const unsigned char*>( in.c_str() ), in.length(), sum );
103 std::ostringstream os;
104 for (
auto& elem : sum )
106 os << std::setfill(
'0' ) << std::setw( 2 ) << std::hex << (int)elem;
bool MD5_Encrypt(const std::string &in, std::string &out)
int stringicmp(const S1 &str1, const S2 &str2)
bool MD5_Compare(const std::string &a, const std::string &b)