#include "stdafx.h"
#include "CgeepApVC6.h"
#include "CgeepApiExample.h"
#include "CgeepApiExample.h"
#include "cgeepapi4x.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
const CString TEMP_DIR = "c:\\temp";
CCgeepApiExample::CCgeepApiExample()
{ ICgeepApi cgeepApi;
if (! cgeepApi.CreateDispatch("cgeepapi4x.CgeepApi"))
{
AfxMessageBox("Dll cgeepapi4x.dll not loaded!", MB_ICONSTOP);
return;
} cgeepApi.setKeyRingDirectory(TEMP_DIR); cgeepApi.generateKeyPair("test1@test.com", "passphrase",
"RSA", 1024, "AES-256", "NEVER");
if (!cgeepApi.isOperationOk())
{
AfxMessageBox("Error : " + cgeepApi.getErrorCode());
AfxMessageBox("Exception: " + cgeepApi.getException());
return;
} cgeepApi.generateKeyPair("test2@test.com", "passphrase",
"RSA", 1024, "AES-256", "NEVER");
if (!cgeepApi.isOperationOk())
{
AfxMessageBox("Error : " + cgeepApi.getErrorCode());
AfxMessageBox("Exception: " + cgeepApi.getException());
return;
} CString list = cgeepApi.listKeys("");
if(!cgeepApi.isOperationOk())
{
AfxMessageBox("Error: " + cgeepApi.getErrorCode());
AfxMessageBox("Exception: " + cgeepApi.getException());
return;
}
AfxMessageBox(list); CString fileIn = TEMP_DIR + "\\text.txt";
CString fileOut = TEMP_DIR + "\\text.txt.pgp"; cgeepApi.encryptSymmetric(fileIn, fileOut, "paspshrase", 0);
if (!cgeepApi.isOperationOk())
{
AfxMessageBox("Error : " + cgeepApi.getErrorCode());
AfxMessageBox("Exception: " + cgeepApi.getException());
return;
} CString fileEncrypted = TEMP_DIR + "\\text.txt.pgp";
CString fileDecrypted = TEMP_DIR + "\\text_decrypted.txt"; cgeepApi.decryptSymmetric(fileEncrypted, fileDecrypted, "paspshrase", 0);
if (!cgeepApi.isOperationOk())
{
AfxMessageBox("Error : " + cgeepApi.getErrorCode());
AfxMessageBox("Exception: " + cgeepApi.getException());
return;
} cgeepApi.resetRecipientsKeys(); cgeepApi.addRecipientKey("test1@test.com"); cgeepApi.addRecipientKey("test2@test.com");
fileIn = TEMP_DIR + "\\text.txt";
fileOut = TEMP_DIR + "\\text.txt.pgp"; cgeepApi.encrypt(fileIn, fileOut, 0);
if (!cgeepApi.isOperationOk())
{
AfxMessageBox("Error : " + cgeepApi.getErrorCode());
AfxMessageBox("Exception: " + cgeepApi.getException());
return;
}
cgeepApi.decrypt(fileEncrypted, fileDecrypted, "test1@test.com", "paspshrase", 0);
if (!cgeepApi.isOperationOk())
{
AfxMessageBox("Error : " + cgeepApi.getErrorCode());
AfxMessageBox("Exception: " + cgeepApi.getException());
return;
}
CString fileClear = TEMP_DIR + "\\text.txt";
CString fileEnc = TEMP_DIR + "\\text.txt.pgp"; cgeepApi.encryptSymmetric(fileClear,
fileEnc,
"paspshrase",
1);
char strPercentProgress[10]; while (cgeepApi.getPercentProcessedForTask(1) < 100)
{
Sleep(1000);
int percentProgress = cgeepApi.getPercentProcessedForTask(1);
sprintf(strPercentProgress,"%d", percentProgress);
CString progress;
progress += "Progress";
progress += strPercentProgress;
progress += "%";
AfxMessageBox(progress);
} if (!cgeepApi.isOperationOkForTask(1))
{
AfxMessageBox("Error : "
+ cgeepApi.getErrorCodeForTask(1));
AfxMessageBox("Exception: "
+ cgeepApi.getExceptionForTask(1));
return;
} AfxMessageBox("Done!");
}
CCgeepApiExample::~CCgeepApiExample()
{
}