#include "CgeepApiXmlRpc.h"
int main(int argc, char* argv[])
{
std::string tempDir;
std::string theOS;
if (getenv("OS") == NULL)
{
theOS = "unknown_probably_unix";
}
else
{
theOS = getenv("OS");
}
if (theOS.find("Windows") != std::string::npos)
{
tempDir = "c:\\TEMP\\";
}
else
{
tempDir = "/tmp/";
}
int port = 8081; std::string host = "127.0.0.1";
if (argc != 3)
{
std::cout << "Usage: CgeepApiXmlRpcExample <serverHost> <serverPort>\n";
}
else
{
port = atoi(argv[2]);
host = argv[1];
} CCgeepApiXmlRpc cgeepApiXmlRpc; cgeepApiXmlRpc.connectToServer((char *)host.c_str(), port); cgeepApiXmlRpc.setKeyRingDirectory((char *)tempDir.c_str());
if (!cgeepApiXmlRpc.isOperationOk())
{
std::cout << "Error : " << cgeepApiXmlRpc.getErrorCode() << "\n";
std::cout << "Exception: " << cgeepApiXmlRpc.getException() << "\n\n";
return -1;
}
else
{
std::cout << "setKeyRingDirectory() done" << "\n";
} cgeepApiXmlRpc.generateKeyPair("test1@test.com", "passphrase",
"RSA", 1024, "AES-256", "NEVER");
if (!cgeepApiXmlRpc.isOperationOk())
{
std::cout << "Error : " << cgeepApiXmlRpc.getErrorCode() << "\n";
std::cout << "Exception: " << cgeepApiXmlRpc.getException() << "\n\n";
return -1;
}
else
{
std::cout << "generateKeyPair() done" << "\n";
} cgeepApiXmlRpc.generateKeyPair("test2@test.com", "passphrase",
"RSA", 1024, "AES-256", "NEVER");
if (!cgeepApiXmlRpc.isOperationOk())
{
std::cout << "Error : " << cgeepApiXmlRpc.getErrorCode() << "\n";
std::cout << "Exception: " << cgeepApiXmlRpc.getException() << "\n\n";
return -1;
}
else
{
std::cout << "generateKeyPair() done" << "\n";
} std::string list = cgeepApiXmlRpc.listKeys("");
if(!cgeepApiXmlRpc.isOperationOk())
{
std::cout << "Error : " << cgeepApiXmlRpc.getErrorCode() << "\n";
std::cout << "Exception: " << cgeepApiXmlRpc.getException() << "\n\n";
return -1;
}
else
{
std::cout << "listKeys() done" << "\n";
}
std::cout << "listKeys: " << list << "\n"; std::string fileIn = tempDir + "text.txt";
std::string fileOut = tempDir + "text.txt.pgp"; cgeepApiXmlRpc.encryptSymmetric((char * ) fileIn.c_str(),
(char * ) fileOut.c_str(),
"passphrase",
0);
if (!cgeepApiXmlRpc.isOperationOk())
{
std::cout << "Error : " << cgeepApiXmlRpc.getErrorCode() << "\n";
std::cout << "Exception: " << cgeepApiXmlRpc.getException() << "\n\n";
return -1;
}
else
{
std::cout << "encryptSymmetric() done" << "\n";
} std::string fileEncrypted = tempDir + "text.txt.pgp";
std::string fileDecrypted = tempDir + "\\text_decrypted.txt"; cgeepApiXmlRpc.decryptSymmetric((char * ) fileEncrypted.c_str(),
(char * ) fileDecrypted.c_str(),
"passphrase",
0);
if (!cgeepApiXmlRpc.isOperationOk())
{
std::cout << "Error : " << cgeepApiXmlRpc.getErrorCode() << "\n";
std::cout << "Exception: " << cgeepApiXmlRpc.getException() << "\n\n";
return -1;
}
else
{
std::cout << "decryptSymmetric() done" << "\n";
} cgeepApiXmlRpc.resetRecipientsKeys(); cgeepApiXmlRpc.addRecipientKey("test1@test.com"); cgeepApiXmlRpc.addRecipientKey("test2@test.com");
fileIn = tempDir + "text.txt";
fileOut = tempDir + "text.txt.pgp"; cgeepApiXmlRpc.encrypt((char * )fileIn.c_str(), (char * )fileOut.c_str(), 0);
if (!cgeepApiXmlRpc.isOperationOk())
{
std::cout << "Error : " << cgeepApiXmlRpc.getErrorCode() << "\n";
std::cout << "Exception: " << cgeepApiXmlRpc.getException() << "\n\n";
return -1;
}
else
{
std::cout << "encrypt() done" << "\n";
}
cgeepApiXmlRpc.decrypt((char * )fileEncrypted.c_str(),
(char * )fileDecrypted.c_str(),
"test1@test.com", "passphrase",
0);
if (!