Advertisement
Advertisement
| 04.04.2008 at 03:14AM PDT, ID: 23295501 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
|
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: |
#include <wincrypto.h>
bool md5(unsigned char hash[16], unsigned char *buf, int len)
{
HCRYPTPROV hCryptProv;
HCRYPTHASH hHash;
BYTE bHash[0x7f];
DWORD dwHashLen = 16;
DWORD cbContent = len;
BYTE* pbContent = (BYTE*)buf;
if(CryptAcquireContext(&hCryptProv,
NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET))
{
if(CryptCreateHash(hCryptProv,
CALG_MD5,
0, 0, &hHash))
{
if(CryptHashData(hHash, pbContent, cbContent, 0))
{
if(CryptGetHashParam(hHash, HP_HASHVAL, bHash, &dwHashLen, 0))
{
memcpy(hash, bHash, 16);
}
else return false;
}
else return false;
}
else return false;
}
else return false;
CryptDestroyHash(hHash);
CryptReleaseContext(hCryptProv, 0);
return true;
}
|
| Microsoft |
| Apple |
| Internet |
| Gamers |
| Digital Living |
| Virus & Spyware |
| Hardware |
| Software |
| ITPro |
| Developer |
| Storage |
| OS |
| Database |
| Security |
| Programming |
| Web Development |
| Networking |
| Other |
| Community Support |
| 04.04.2008 at 05:10AM PDT, ID: 21280779 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: |
AnsiString md5 (AnsiString Source)
{
HCRYPTPROV hCryptProv;
HCRYPTHASH hHash;
BYTE bHash[0x7f];
DWORD dwHashLen = 16;
DWORD cbContent = len;
BYTE* pbContent = (BYTE*)buf;
// New variables -- originally on the function's parameter list
unsigned char hash [16+1];// The buffer where the md5 hash will be built
unsigned char *buf; // Originally this was the buffer to hash
int len; // Original buffer length;
len = Source.Length ();
buf = (unsigned char*)Source.c_ptr ();
if (CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET))
{
if (CryptCreateHash (hCryptProv, CALG_MD5, 0, 0, &hHash))
{
if (CryptHashData (hHash, pbContent, cbContent, 0))
{
if (CryptGetHashParam (hHash, HP_HASHVAL, bHash, &dwHashLen, 0))
{
memcpy(hash, bHash, 16);
}
else return "";
}
else return "";
}
else return "";
}
else return "";
CryptDestroyHash(hHash);
CryptReleaseContext(hCryptProv, 0);
hash[16] = 0; // Append a stringterminator to the hash
return (AnsiString) (hash);
}
|
| 04.04.2008 at 05:28AM PDT, ID: 21280896 |
| 04.04.2008 at 05:35AM PDT, ID: 21280957 |
| 04.04.2008 at 06:00AM PDT, ID: 21281155 |
| 04.04.2008 at 06:20AM PDT, ID: 21281339 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: |
class mymd5
{
public:
bool md5 (AnsiString);
char DisplayValue [17];
private:
unsigned char hash[16];
bool Success;
};
bool mymd5::md5 (AnsiString Source)
{
Success = md5 (hash, (unsigned char*)Source.c_str (), Source.Length);
if (Success)
{
for (int idx = 0; unsigned char *ptr = hash; ++idx, ++ptr)
{
DisplayValue[idx*2] = (char*)"0123456789ABCDEF"[(*ptr)>>4];
DisplayValue[idx*2+1] = (char*)"0123456789ABCDEF"[(*ptr)& 0xF)];
}
DisplayValue[16] = 0;
}
else
DispalyValue[0] = 0;
return Success;
}
|
| 04.04.2008 at 07:37AM PDT, ID: 21282186 |
| 04.04.2008 at 10:20AM PDT, ID: 21283791 |
| 04.04.2008 at 01:58PM PDT, ID: 21285606 |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: |
String TForm1::MD5(AnsiString Source)
{
unsigned char hash[16];
bool Success;
char DisplayValue [17];
Success = MD5Hex(hash, (unsigned char*)Source.c_str (), Source.Length());
if (Success)
{
static const char HexDigit[16] = "0123456789ABCDEF";
for (int idx = 0; unsigned char *ptr = hash; ++idx, ++ptr)
{
DisplayValue[idx*2] = HexDigit [(*ptr)>>4];
DisplayValue[idx*2+1] = HexDigit [(*ptr)&0xF];
}
DisplayValue[16] = 0;
return (String)DisplayValue;
}
return "";
}
bool TForm1::MD5Hex(unsigned char hash[16], unsigned char *buf, int len)
{
HCRYPTPROV hCryptProv;
HCRYPTHASH hHash;
BYTE bHash[0x7f];
DWORD dwHashLen = 16;
DWORD cbContent = len;
BYTE* pbContent = (BYTE*)buf;
if(CryptAcquireContext(&hCryptProv,
NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_MACHINE_KEYSET))
{
if(CryptCreateHash(hCryptProv,
CALG_MD5, // wincrypt.h
0, 0, &hHash))
{
if(CryptHashData(hHash, pbContent, cbContent, 0))
{
if(CryptGetHashParam(hHash, HP_HASHVAL, bHash, &dwHashLen, 0))
{
memcpy(hash, bHash, 16);
}
else return false;
}
else return false;
}
else return false;
}
else return false;
CryptDestroyHash(hHash);
CryptReleaseContext(hCryptProv, 0);
return true;
}
|