Форум — Ответы ( К темам )
| ? | Igos: Привязка ПО к машине (31-03-2003 13:01:48) |
| Хотелось бы узнать привязывает ли кто ПО к железу, и если да — то как ? Я например делаю это сл. образом: получаю VolumeSerialNumber, с помощью CryptoApi, шифрую эти данные, добавляя в опр. месте некоторые постоянные величины, кот. мне нужны в проге и все. До сих пор все вроде работает, за искл. старых брендов. Если что могу обьяснить более подробно (дабы принять критику), правда сначала винт восстановлю. | |
| Владимир (31-03-2003 20:00:25) | |
|
Во-первых, поместите код, как вы это делаете, всегда интересно посмотреть, поучиться. На форуме был подобный вопрос, по привязке к номеру винчестера http://rxlib.ru/arhp/id1673.html и http://rxlib.ru/arhp/id230.html | |
| Владимир (02-04-2003 13:30:23) | |
Получено от Igos (по теме Привязка ПО к машине):
//---------------------------------------------------------------------------
void Encrypt(AnsiString S)
{
int OutLen;
char *StrToEncrypt=S.c_str();
char OutString[255];
HCRYPTPROV hProv = 0;
HCRYPTKEY hKey = 0;
HCRYPTKEY hXchgKey = 0;
bool Result;
DWORD dwCount = S.Length();
DWORD dwBlobLen;
Result=CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0);
if(!Result)
{
Result=CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET);
if(!Result)
{
if(hProv != 0) CryptReleaseContext(hProv, 0);
return ;
}
}
Result=CryptGetUserKey(hProv, AT_KEYEXCHANGE, &hXchgKey);
if(!Result)
{
Result=CryptGenKey(hProv, AT_KEYEXCHANGE, CRYPT_EXPORTABLE, &hKey);
if(!Result)
{
if(hKey != 0) CryptDestroyKey(hKey);
if(hXchgKey != 0) CryptDestroyKey(hXchgKey);
if(hProv != 0) CryptReleaseContext(hProv, 0);
return ;
}
Result=CryptGetUserKey(hProv, AT_KEYEXCHANGE, &hXchgKey);
if(!Result)
{
if(hKey != 0) CryptDestroyKey(hKey);
if(hXchgKey != 0) CryptDestroyKey(hXchgKey);
if(hProv != 0) CryptReleaseContext(hProv, 0);
return ;
}
}
Result=CryptGenKey(hProv, CALG_RC4, CRYPT_EXPORTABLE, &hKey);
if(!Result)
{
if(hKey != 0) CryptDestroyKey(hKey);
if(hXchgKey != 0) CryptDestroyKey(hXchgKey);
if(hProv != 0) CryptReleaseContext(hProv, 0);
return ;
}
Result=CryptExportKey(hKey, hXchgKey, SIMPLEBLOB, 0, NULL, &dwBlobLen);
if(!Result)
{
if(hKey != 0) CryptDestroyKey(hKey);
if(hXchgKey != 0) CryptDestroyKey(hXchgKey);
if(hProv != 0) CryptReleaseContext(hProv, 0);
return ;
}
BYTE *pbKeyBlob=new BYTE[dwBlobLen];
Result=CryptExportKey(hKey, hXchgKey, SIMPLEBLOB, 0, pbKeyBlob, &dwBlobLen);
if(!Result)
{
free(pbKeyBlob);
if(hKey != 0) CryptDestroyKey(hKey);
if(hXchgKey != 0) CryptDestroyKey(hXchgKey);
if(hProv != 0) CryptReleaseContext(hProv, 0);
return ;
}
Main->dwBlobLen=dwBlobLen;
memcpy(Main->pbKeyBlob, pbKeyBlob, dwBlobLen);
free(pbKeyBlob);
Result=CryptEncrypt(hKey, 0, true, 0, NULL, &dwCount, BUFFER_SIZE);
if(!Result)
{
if(hKey != 0) CryptDestroyKey(hKey);
if(hXchgKey != 0) CryptDestroyKey(hXchgKey);
if(hProv != 0) CryptReleaseContext(hProv, 0);
return ;
}
strcpy(OutString,StrToEncrypt);
OutLen=dwCount;
dwCount = S.Length();
Result=CryptEncrypt(hKey, 0, true, 0, OutString, &dwCount, OutLen);
if(!Result)
{
if(hKey != 0) CryptDestroyKey(hKey);
if(hXchgKey != 0) CryptDestroyKey(hXchgKey);
if(hProv != 0) CryptReleaseContext(hProv, 0);
return ;
}
Main->OutLen=OutLen;
memcpy(Main->OutString, OutString, OutLen);
if(hKey != 0) CryptDestroyKey(hKey);
if(hXchgKey != 0) CryptDestroyKey(hXchgKey);
if(hProv != 0) CryptReleaseContext(hProv, 0);
return ;
}
//---------------------------------------------------------------------------
AnsiString Decrypt(void)
{
HCRYPTPROV hProv = 0;
HCRYPTKEY hKey = 0;
DWORD dwCount;
DWORD dwBlobLen;
char pbBuffer[BLOCK_SIZE];
char DecryptedStr[255]; //=StringToDecrypt.c_str();
dwBlobLen=Main->dwBlobLen;
BYTE *pbKeyBlob=new BYTE[dwBlobLen];
dwCount=Main->OutLen;
//pbKeyBlob="x01x02";
memcpy(pbKeyBlob,pbKeyBlob,dwBlobLen);
memcpy(pbKeyBlob,Main->pbKeyBlob,dwBlobLen);
memcpy(DecryptedStr,Main->OutString,dwCount);
bool Result;
Result=CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0);
if(!Result)
{
Result=CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_NEWKEYSET);
if(!Result)
{
if(hProv != 0) CryptReleaseContext(hProv, 0);
return "";
}
}
Result= CryptImportKey(hProv, pbKeyBlob, dwBlobLen, 0, 0, &hKey);
if(!Result)
{
free(pbKeyBlob);
if(hKey != 0) CryptDestroyKey(hKey);
if(hProv != 0) CryptReleaseContext(hProv, 0);
return "";
}
memcpy(pbBuffer, DecryptedStr, dwCount);
Result=CryptDecrypt(hKey, 0, true, 0, pbBuffer, &dwCount);
if(!Result)
{
free(pbKeyBlob);
if(hKey != 0) CryptDestroyKey(hKey);
if(hProv != 0) CryptReleaseContext(hProv, 0);
return "";
}
pbBuffer[dwCount]=0;
if(pbKeyBlob) free(pbKeyBlob);
if(hKey != 0) CryptDestroyKey(hKey);
if(hProv != 0) CryptReleaseContext(hProv, 0);
return (AnsiString)pbBuffer;
}
//---------------------------------------------------------------------------
AnsiString VolSerNum(void)
{
double b;
LPTSTR lpVolumeNameBuffer = new char[20];
LPDWORD lpVolumeSerialNumber = new DWORD;
LPDWORD lpMaximumComponentLength = new DWORD;
LPDWORD lpFileSystemFlags = new DWORD;
LPTSTR lpFileSystemNameBuffer = new char[20];
bool Result;
Result=GetVolumeInformation(NULL, lpVolumeNameBuffer, 20, lpVolumeSerialNumber,
lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer,10);
if (Result)
{
b= *lpVolumeSerialNumber;
return (AnsiString)b;
}
else return "";
}
//---------------------------------------------------------
| |
| Георгий (02-04-2003 19:59:58) | |
|
А теперь можно хоть схематически описать алгоритм работы с этими функциями и работу этих ф-ций а так же, если возможно, описание API использованных здесь... | |