Skip to main content

cpp_file.cpp

/*****************************************************************************************
* cpp_file.cpp
*
* Note: See Tricryption Engine SDK for details on how to set the project environment.
*
******************************************************************************************/

#include <iostream>
#include "teconnection.h"
#include "teagent.h"
#include "teexception.h"

using namespace ERUCES;
using namespace std;


int main()
{
string strServerName = "localhost"; // server name
long lPort = 5050; // port number
string strUsername = "ls"; // username
string strPassword = "password"; // password

try
{
auto_ptr<TEConnection> conn =
TEConnection::createInstance(TEConnection::SecureConnection);

// Open connection to the server
conn->open(strServerName, lPort, strUsername, strPassword);

cout << "Connected to " << strServerName << " at " << lPort
<< " as " << strUsername << "\n" << endl;

// Create a TEAgentFile object
TEAgentFile file;

// Set original data file and encrypted output file
file.setInputFileName(".\\Test.txt");
file.setOutputFileName(".\\Test.txt.eru");

// Encrypt file
file.attachConnection(conn.get());
file.encrypt();
file.detachConnection();

cout << "File " << file.getInputFileName() << " was encrypted, the output file is " <<
file.getOutputFileName() << endl;

file.clear();
// Set encrypted data file and decrypted output file
file.setInputFileName(".\\Test.txt.eru");
file.setOutputFileName(".\\Test.txt.out");

// Decrypt file
file.attachConnection(conn.get());
file.decrypt();
file.detachConnection();

cout << "File " << file.getInputFileName() << " was decrypted, the output file is " <<
file.getOutputFileName() << endl;

// Close conneciton
conn->close();

cout << "Disconnected from server." << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}

return 0;
}