#include #include #include int main(int argc, char **argv) { HCRYPTPROV prov1, prov2, prov3; HCRYPTKEY hKey1, hKey2, hKey3, hKeyCrypt, hKeyDecrypt; unsigned char Data[30]; BYTE DataPom[1024]; CRYPT_DATA_BLOB blob; long Alg; unsigned long Velikost2 = 1024,Velikost = 12; DWORD cbServerBlob, pSize; //BYTE rgbServerBlob[2048]; DWORD dwNJ=0; // Specify 11 bytes of salt. BYTE rgbSalt[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B}; CRYPT_DATA_BLOB sSaltData; sSaltData.pbData = rgbSalt; sSaltData.cbData = sizeof(rgbSalt); Alg = CALG_RC4; strcpy(Data, "HELLO WORLD!"); if (!CryptAcquireContext(&prov1, "MyDSS_DH_Container", MS_ENH_DSS_DH_PROV, PROV_DSS_DH, 0)) { printf("container is not defined \n"); if (!CryptAcquireContext(&prov1, "MyDSS_DH_Container", MS_ENH_DSS_DH_PROV, PROV_DSS_DH, CRYPT_NEWKEYSET)) { printf("Error 1: %x(%d)\n", GetLastError(), GetLastError()); } else { printf("trying to generate new key \n"); if (!CryptGenKey(prov1, CALG_DH_SF, (512 << 16) | CRYPT_EXPORTABLE | CRYPT_NO_SALT , &hKey1)) { printf("Error 3: %x(%d)\n", GetLastError(), GetLastError()); } } } //printf("prov1=%d hKey1=%d \n", prov1, hKey1); if ( 1==1) { printf("aquiring key handle for existing key \n"); if (!CryptGetUserKey( prov1, CALG_DH_SF, &hKey1)) { printf("Error 3: %x(%d)\n", GetLastError(), GetLastError()); } } printf("prov1=%d hKey1=%d \n", prov1, hKey1); if (!CryptAcquireContext(&prov2, "DHPregen", MS_ENH_DSS_DH_PROV, PROV_DSS_DH, 0)) { if (!CryptAcquireContext(&prov2, "DHPregen", MS_ENH_DSS_DH_PROV, PROV_DSS_DH, CRYPT_NEWKEYSET)) { printf("Error 1: %x(%d)\n", GetLastError(), GetLastError()); } } if (!CryptGenKey(prov2, CALG_DH_EPHEM, (512 << 16) | CRYPT_PREGEN | CRYPT_EXPORTABLE | CRYPT_NO_SALT , &hKey2)) { printf("Error 6: %x(%d)\n", GetLastError(), GetLastError()); } printf("prov2=%d hKey1=%d \n", prov2, hKey2); Velikost2 = 0; if (!CryptSetKeyParam(hKey1, KP_X, NULL, 0)) { printf("Error 13: %x(%d)\n", GetLastError(), GetLastError()); } if (!CryptGetKeyParam(hKey1, KP_G, 0, &Velikost2, 0)) { printf("Error 9: %x(%d)\n", GetLastError(), GetLastError()); } printf("BufSize=%d \n", Velikost2); for (dwNJ=0;dwNJ