I wrote the following programs based on crypto++ as part of an application and tried to run the app after appropriately adding a crypto++ dynamic link library compiled from source code obtained from the official Crypto++ GitHub repository. Unfortunate visual studio reported a linkage error that had to do with std::string. After making efforts for some hours to resolve the linkage error, I decided it is best I work with the source code such that I can easily locate error points. I tried to use the header files to determine the implementation files but only ended up with linkage errors.
How can one determine all the necessary implementation files for a program.
//The basic header files
include "modes.h"
#include "aes.h"
#include "filters.h"
#include "rijndael.h"
#include "osrng.h"
First program
std::string encryptMessage(const std::string& message, const std::string& key)
{
using namespace CryptoPP;
byte iv[AES::BLOCKSIZE];
memset(iv, 0x00, AES::BLOCKSIZE); std::string encryptedMessage;
try
{
CBC_Mode<AES>::Encryption encryption;
encryption.SetKeyWithIV((const byte*)key.data(), key.size(), iv);
StringSource(message, true,
new StreamTransformationFilter(encryption,
new StringSink(encryptedMessage)
)
);
}
catch (const Exception& ex)
{
UNREFERENCED_PARAMETER(ex);
return std::string();
}
return encryptedMessage;
}
The second program
std::string decryptMessage(const std::string& encryptedMessage, const std::string& key)
{
using namespace CryptoPP;
byte iv[AES::BLOCKSIZE];
memset(iv, 0x00, AES::BLOCKSIZE); std::string decryptedMessage;
try
{
CBC_Mode<AES>::Decryption decryption;
decryption.SetKeyWithIV((const byte*)key.data(), key.size(), iv);
StringSource(encryptedMessage, true,
new StreamTransformationFilter(decryption,
new StringSink(decryptedMessage)
)
);
}
catch (const Exception& ex)
{
UNREFERENCED_PARAMETER(ex);
return std::string();
}
return decryptedMessage;
}
The third program
std::string CreateKey()
{
CryptoPP::AutoSeededRandomPool prng;
byte Key[CryptoPP::AES::DEFAULT_KEYLENGTH];
prng.GenerateBlock(Key, sizeof(Key));
std::string stKey;
for (int i = 0; i < CryptoPP::AES::DEFAULT_KEYLENGTH; i++)
{
stKey.push_back(Key[i]);
}
return stKey;
}
What I have tried:
I spent two days trying to resolve the associated issues with numerous googlng.