//CRC32 static DWORD crc32table[256]; static bool crc32Intalized; DWORD crc32Hash(const void *data, DWORD size); DWORD Crypt::crc32Hash(const void *data, DWORD size) { if(crc32Intalized == false) { register DWORD crc; for(register DWORD i = 0; i < 256; i++) { crc = i; for(register DWORD j = 8; j > 0; j--) { if(crc & 0x1)crc = (crc >> 1) ^ 0xEDB88320L; else crc >>= 1; } crc32table[i] = crc; } crc32Intalized = true; } register DWORD cc = 0xFFFFFFFF; for(register DWORD i = 0; i < size; i++)cc = (cc >> 8) ^ crc32table[(((LPBYTE)data)[i] ^ cc) & 0xFF]; return ~cc; } //MD5 #define MD5HASH_SIZE 16 bool _md5Hash(LPBYTE output, void *inputData, DWORD dataSize); bool Crypt::_md5Hash(LPBYTE output, void *inputData, DWORD dataSize) { bool r = false; HCRYPTPROV hashProv; if(CWA(advapi32, CryptAcquireContextW)(&hashProv, NULL, NULL, PROV_RSA_FULL /*Èìåííî ýòî çíà÷åíèå, íå êàêîãî èíîãî.*/, CRYPT_VERIFYCONTEXT | CRYPT_SILENT) != FALSE) { HCRYPTHASH hashHandle; if(CWA(advapi32, CryptCreateHash)(hashProv, CALG_MD5, 0, 0, &hashHandle) == TRUE) { DWORD hashLen = MD5HASH_SIZE; if(CWA(advapi32, CryptHashData)(hashHandle, (LPBYTE)inputData, dataSize, 0) == TRUE && CWA(advapi32, CryptGetHashParam)(hashHandle, HP_HASHVAL, output, &hashLen, 0) == TRUE && hashLen == MD5HASH_SIZE)r = true; CWA(advapi32, CryptDestroyHash)(hashHandle); } CWA(advapi32, CryptReleaseContext)(hashProv, 0); } return r; }
lundi 28 janvier 2013
CRC32 and MD5 hash c++
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire