//--------------------------------------------------------------------------- #include #pragma hdrstop #include "main.h" #include "setup.h" #include "test.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TmainF *mainF; //--------------------------------------------------------------------------- __fastcall TmainF::TmainF(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TmainF::N3Click(TObject *Sender) { setupF->Visible=true; } //--------------------------------------------------------------------------- void __fastcall TmainF::N2Click(TObject *Sender) { #define PARAMETER1 10 #define PARAMETER2 9 #define PARAMETER3 8 #define PARAMETER4 7 #define PARAMETER5 6 #define PARAMETER6 5 #define PARAMETER7 4 #define PARAMETER8 3 #define PARAMETER9 2 #define PARAMETER10 1 HANDLE hEvent=NULL; HCRYPTPROV hProv=NULL; HCRYPTKEY hKey=NULL; HCRYPTKEY hKey2=NULL; HCRYPTPROV hHash=NULL; HCRYPTKEY hPub=NULL; HCRYPTKEY hUser=NULL; CHAR pszMyName[64]=""; Memo1->Lines->Add("==TEST=="); char* name_prov = new char[setupF->Edit1->Text.Length()+1]; StrCopy(name_prov, setupF->Edit1->Text.c_str()); int type_provr=StrToInt(setupF->Edit2->Text); /*char* type_provr = new char[setupF->Edit2->Text.Length()+1]; StrCopy(type_provr, setupF->Edit2->Text.c_str()); */ if (RCRYPT_FAILED(CryptAcquireContext(&hProv, NULL,name_prov, type_provr, 0))) { Memo1->Lines->Add("CryptAcquireConext - Test Failed"); } else { Memo1->Lines->Add("CryptAcquireConext - SUCCEED"); } if (RCRYPT_FAILED(CryptGenKey(hProv,(int) PARAMETER2,PARAMETER3,&hKey))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptGenKey - Access violation"); } else { Memo1->Lines->Add("CryptGenKey - Test Failed"); } } else { Memo1->Lines->Add("CryptGenKey - SUCCEED"); } if (RCRYPT_FAILED(CryptDestroyKey(hKey))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptDestroyKey - Access violation"); } else { Memo1->Lines->Add("CryptDestroyKey - Test Failed"); } } else { Memo1->Lines->Add("CryptDestroyKey - SUCCEED"); } if (RCRYPT_FAILED(CryptGenKey(hProv,(int) PARAMETER2,PARAMETER3,&hKey))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptGenKey - Access violation"); } else { Memo1->Lines->Add("CryptGenKey - Test Failed"); } } else { Memo1->Lines->Add("CryptGenKey - SUCCEED"); } if (RCRYPT_FAILED(CryptSetKeyParam(hKey, PARAMETER2, (BYTE *) PARAMETER3, PARAMETER4))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptSetKeyParam - Access violation"); } else { Memo1->Lines->Add("CryptSetKeyParam - Test Failed"); } } else { Memo1->Lines->Add("CryptSetKeyParam - SUCCEED"); } if (RCRYPT_FAILED(CryptGetKeyParam(hKey, PARAMETER2, (BYTE *) PARAMETER3, (DWORD *) PARAMETER4, PARAMETER5))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptGetKeyParam - Access violation"); } else { Memo1->Lines->Add("CryptGetKeyParam - Test Failed"); } } else { Memo1->Lines->Add("CryptGetKeyParam - SUCCEED"); } if (RCRYPT_FAILED(CryptSetProvParam(hProv, PARAMETER2, (BYTE *) PARAMETER3, PARAMETER4))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptSetProvParam - Access violation"); } else { Memo1->Lines->Add("CryptSetProvParam - Test Failed"); } } else { Memo1->Lines->Add("CryptSetProvParam - SUCCEED"); } if (RCRYPT_FAILED(CryptGetProvParam(hProv, PARAMETER2, (BYTE *) PARAMETER3, (DWORD *) PARAMETER4, PARAMETER5))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptGetProvParam - Access violation"); } else { Memo1->Lines->Add("CryptGetProvParam - Test Failed"); } } else { Memo1->Lines->Add("CryptGetProvParam - SUCCEED"); } if (RCRYPT_FAILED(CryptGenRandom(hProv, PARAMETER2, (BYTE *) PARAMETER3))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptGenRandom - Access violation"); } else { Memo1->Lines->Add("CryptGenRandom - Test Failed"); } } else { Memo1->Lines->Add("CryptGenRandom - SUCCEED"); } if (RCRYPT_FAILED(CryptGetUserKey(hProv, PARAMETER2, &hUser))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptGetUserKey - Access violation"); } else { Memo1->Lines->Add("CryptGetUserKey - Test Failed"); } } else { Memo1->Lines->Add("CryptGetUserKey - SUCCEED"); } if (RCRYPT_FAILED(CryptGenKey(hProv, (int) PARAMETER2, PARAMETER3, &hPub))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptGenKey - Access violation"); } else { Memo1->Lines->Add("CryptGenKey - Test Failed"); } } else { Memo1->Lines->Add("CryptGenKey - SUCCEED"); } if (RCRYPT_FAILED(CryptExportKey(hKey, hPub, PARAMETER3, PARAMETER4, (BYTE *) PARAMETER5, (DWORD *) PARAMETER6))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptExportKey - Access violation"); } else { Memo1->Lines->Add("CryptExportKey - Test Failed"); } } else { Memo1->Lines->Add("CryptExportKey - SUCCEED"); } if (RCRYPT_FAILED(CryptImportKey(hProv, (BYTE *) PARAMETER2, PARAMETER3, hUser, PARAMETER5, &hKey2))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptImportKey - Access violation"); } else { Memo1->Lines->Add("CryptImportKey - Test Failed"); } } else { Memo1->Lines->Add("CryptImportKey - SUCCEED"); } if (RCRYPT_FAILED(CryptCreateHash(hProv, (int) PARAMETER2, hKey, PARAMETER4, &hHash))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptCreateHash - Access violation"); } else { Memo1->Lines->Add("CryptCreateHash - Test Failed"); } } else { Memo1->Lines->Add("CryptCreateHash - SUCCEED"); } if (RCRYPT_FAILED(CryptSetHashParam(hHash, PARAMETER2, (BYTE *) PARAMETER3, PARAMETER4))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptSetHashParam - Access violation"); } else { Memo1->Lines->Add("CryptSetHashParam - Test Failed"); } } else { Memo1->Lines->Add("CryptSetHashParam - SUCCEED"); } if (RCRYPT_FAILED(CryptGetHashParam(hHash, PARAMETER2, (BYTE *) PARAMETER3, (DWORD *) PARAMETER4, PARAMETER5))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptGetHashParam - Access violation"); } else { Memo1->Lines->Add("CryptGetHashParam - Test Failed"); } } else { Memo1->Lines->Add("CryptGetHashParam - SUCCEED"); } if (RCRYPT_FAILED(CryptHashData(hHash, (BYTE *) PARAMETER2, PARAMETER3, PARAMETER4))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptHashData - Access violation"); } else { Memo1->Lines->Add("CryptHashData - Test Failed"); } } else { Memo1->Lines->Add("CryptHashData - SUCCEED"); } if (RCRYPT_FAILED(CryptHashSessionKey(hHash, hKey, PARAMETER3))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptHashSessionKey - Access violation"); } else { Memo1->Lines->Add("CryptHashSessionKey - Test Failed"); } } else { Memo1->Lines->Add("CryptHashSessionKey - SUCCEED"); } if (RCRYPT_FAILED(CryptEncrypt(hKey, hHash, (BOOL) PARAMETER3, PARAMETER4, (BYTE *) PARAMETER5, (DWORD *) PARAMETER6, PARAMETER7))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptEncrypt - Access violation"); } else { Memo1->Lines->Add("CryptEncrypt - Test Failed"); } } else { Memo1->Lines->Add("CryptEncrypt - SUCCEED"); } if (RCRYPT_FAILED(CryptDecrypt(hKey, hHash, (BOOL) PARAMETER3, PARAMETER4, (BYTE *) PARAMETER5, (DWORD *) PARAMETER6))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptDecrypt - Access violation"); } else { Memo1->Lines->Add("CryptDecrypt - Test Failed"); } } else { Memo1->Lines->Add("CryptDecrypt - SUCCEED"); } if (RCRYPT_FAILED(CryptDeriveKey(hProv, (int) PARAMETER2, hHash, PARAMETER4, &hKey2))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptDeriveKey - Access violation"); } else { Memo1->Lines->Add("CryptDeriveKey - Test Failed"); } } else { Memo1->Lines->Add("CryptDeriveKey - SUCCEED"); } if (RCRYPT_FAILED(CryptSignHash(hHash, PARAMETER2, "string", PARAMETER4, (BYTE *) PARAMETER5, (DWORD *) PARAMETER6))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptSignHash - Access violation"); } else { Memo1->Lines->Add("CryptSignHash - Test Failed"); } } else { Memo1->Lines->Add("CryptSignHash - SUCCEED"); } if (RCRYPT_FAILED(CryptVerifySignature(hHash, (BYTE *) PARAMETER2, PARAMETER3, hPub, "string", PARAMETER6))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptVerifySignature - Access violation"); } else { Memo1->Lines->Add("CryptVerifySignature - Test Failed"); } } else { Memo1->Lines->Add("CryptVerifySignature - SUCCEED"); } if (RCRYPT_FAILED(CryptDestroyHash(hHash))) { if (GetLastError() == ERROR_INVALID_PARAMETER) { Memo1->Lines->Add("CryptDestroyHash - Access violation"); } else { Memo1->Lines->Add("CryptDestroyHash - Test Failed"); } } else { Memo1->Lines->Add("CryptDestroyHash - SUCCEED"); } if (RCRYPT_FAILED(CryptReleaseContext(hProv, PARAMETER2))) { Memo1->Lines->Add("CryptReleaseContext - FAILED"); } else { Memo1->Lines->Add("CryptReleaseContext - SUCCEED"); } } //---------------------------------------------------------------------------