c++ - MD5 function not functioning properly -
this current md5 function. when used on windows 8.1 returns value, when run on windows 7 returns value 50% of time. pretty peculiar me. ideas?
it turns out dodgy on both win7 , win8. apparently call cryptgethashparam fails error_more_data.
std::string md5(std::string input) { hcryptprov cryptprov; hcrypthash crypthash; byte byteshash[33];//! dword dwhashlen; std::string final; if (cryptacquirecontext(&cryptprov,null, null, prov_rsa_full, crypt_verifycontext | crypt_machine_keyset)) { if (cryptcreatehash(cryptprov, calg_md5, 0, 0, &crypthash)) { if (crypthashdata(crypthash, (byte*)input.c_str(), input.length(), 0)) { if (cryptgethashparam(crypthash, hp_hashval, byteshash, &dwhashlen, 0)) { final.clear(); std::string hexcharset = "0123456789abcdef"; (int j = 0; j < 16; j++) { final += hexcharset.substr(((byteshash[j] >> 4) & 0xf), 1); final += hexcharset.substr(((byteshash[j]) & 0x0f), 1); } } } } } cryptdestroyhash(crypthash); cryptreleasecontext(cryptprov, 0); return final; } int _tmain(int argc, _tchar* argv[]) { char *pp = "derp"; std::string derp = md5(std::string(pp)); printf("%s\n", derp.c_str()); system("pause"); return 0; }
i have fantastic idea: add else clauses conditions know 1 failing. put output in clauses can see detail on error conditions. know wrong function.
Comments
Post a Comment