While trying to use the following crypto++ based code in my WIN32 project,I got the following link errors.
What I basically did was to specify the directory where all the .cpp and .h source file of Crypto++ files are located as "Additional include directory" in VS property setting.Note that all the .cpp and .h source files of Crypto++ are in the same directory.
Next, I specified Cryptopp.lib as "Additional Dependency" in VS property setting.
Next, I specified the directory where the debug version of Cryptopp.lib is located as "AdditionalLibrary directory" in VS property setting.
Finally, I copied the dll and placed it in the same directory where my app's executable is.
So,what have I done wrong>>
#include "stdafx.h"
#include "EncryptDecrypt.h"
#include "osrng.h"
using CryptoPP::AutoSeededRandomPool;
#include "filters.h"
using CryptoPP::StringSink;
using CryptoPP::StringSource;
using CryptoPP::AuthenticatedEncryptionFilter;
using CryptoPP::AuthenticatedDecryptionFilter;
#include "aes.h"
using CryptoPP::AES;
#include "ccm.h"
using CryptoPP::CCM;
#include "eax.h"
using CryptoPP::EAX;
#include "gcm.h"
using CryptoPP::GCM;
#include "base64.h"
<pre lang="C++">
enum class EnryptType
{
ENC_EAX, ENC_GCM, ENC_CCM
}
bool Base64Encode(std::string &ciphertext)
{
std::string encoded;
try
{
CryptoPP::StringSource(ciphertext, true,
new CryptoPP::Base64Encoder(new CryptoPP::StringSink(encoded)));
}
catch (const std::exception& ex)
{
UNREFERENCED_PARAMETER(ex);
return false;
}
ciphertext = encoded;
return true;
}
<pre lang="C++">
bool Base64Decode(std::string &encoded)
{
std::string ciphertext;
try
{
CryptoPP::StringSource(encoded, true,
new CryptoPP::Base64Decoder(new CryptoPP::StringSink(ciphertext)));
}
catch (const std::exception& ex)
{
UNREFERENCED_PARAMETER(ex);
return false;
}
encoded = ciphertext;
return true;
}
<pre lang="C++">
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;
}
<pre lang="C++">
bool EncryptData(std::string& message, const std::string& key, EncryptType eEncryptType)
{
byte iv[AES::BLOCKSIZE];
memset(iv, 0x00, AES::BLOCKSIZE);
std::string encryptedMessage;
try
{
if (eEncryptType == EncryptType::ENC_EAX)
{
EAX<AES>::Encryption encryptor;
encryptor.SetKeyWithIV((const byte*)key.data(), sizeof(key), iv, sizeof(iv));
StringSource(message, true,
new AuthenticatedEncryptionFilter(
encryptor,
new StringSink(encryptedMessage)
)
);
}
else if (eEncryptType == EncryptType::ENC_GCM)
{
GCM<AES>::Encryption encryptor;
encryptor.SetKeyWithIV((const byte*)key.data(), sizeof(key), iv);
StringSource(message, true,
new AuthenticatedEncryptionFilter(
encryptor,
new StringSink(encryptedMessage)
)
);
}
else if (eEncryptType == EncryptType::ENC_CCM)
{
const int TAG_SIZE = 12;
CCM<AES, TAG_SIZE>::Encryption encryptor;
encryptor.SetKeyWithIV((const byte*)key.data(), sizeof(key), iv);
encryptor.SpecifyDataLengths(0, message.size());
StringSource(message, true,
new AuthenticatedEncryptionFilter(
encryptor,
new StringSink(encryptedMessage)
)
);
}
}
catch (const std::exception& ex)
{
UNREFERENCED_PARAMETER(ex);
return false;
}
message = encryptedMessage;
return true;
}
<pre lang="C++"><
bool DecryptData(std::string& encryptedMessage, const std::string& key, EncryptType eEncryptType)
{
byte iv[AES::BLOCKSIZE];
memset(iv, 0x00, AES::BLOCKSIZE);
std::string decryptedMessage;
try
{
if (eEncryptType == EncryptType::ENC_EAX)
{
EAX<AES>::Decryption decryptor;
decryptor.SetKeyWithIV((const byte*)key.data(), sizeof(key), iv, sizeof(iv));
StringSource(encryptedMessage, true,
new AuthenticatedDecryptionFilter(
decryptor,
new StringSink(decryptedMessage)
)
);
}
else if (eEncryptType == EncryptType::ENC_GCM)
{
GCM<AES>::Decryption decryptor;
decryptor.SetKeyWithIV((const byte*)key.data(), sizeof(key), iv);
StringSource(encryptedMessage, true,
new AuthenticatedDecryptionFilter(
decryptor,
new StringSink(decryptedMessage)
)
);
}
else if (eEncryptType == EncryptType::ENC_CCM)
{
const int TAG_SIZE = 12;
CCM<AES, TAG_SIZE>::Decryption decryptor;
decryptor.SetKeyWithIV((const byte*)key.data(), sizeof(key), iv);
decryptor.SpecifyDataLengths(0, encryptedMessage.size() - TAG_SIZE);
StringSource(encryptedMessage, true,
new AuthenticatedDecryptionFilter(
decryptor,
new StringSink(decryptedMessage)
)
);
}
}
catch (const std::exception& ex)
{
UNREFERENCED_PARAMETER(ex);
return false;
}
encryptedMessage = decryptedMessage;
return true;
}
The following are the link errors:
<pre>Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol "protected: virtual void __thiscall CryptoPP::EAX_Base::AuthenticateLastFooterBlock(unsigned char *,unsigned int)" (?AuthenticateLastFooterBlock@EAX_Base@CryptoPP@@MAEXPAEI@Z) ResultSheets C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj 1
Error LNK2019 unresolved external symbol "public: virtual void __thiscall CryptoPP::Base64Encoder::IsolatedInitialize(class CryptoPP::NameValuePairs const &)" (?IsolatedInitialize@Base64Encoder@CryptoPP@@UAEXABVNameValuePairs@2@@Z) referenced in function "public: __thiscall CryptoPP::Base64Encoder::Base64Encoder(class CryptoPP::BufferedTransformation *,bool,int)" (??0Base64Encoder@CryptoPP@@QAE@PAVBufferedTransformation@1@_NH@Z) ResultSheets C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj 1
Error LNK2001 unresolved external symbol "public: virtual void __thiscall CryptoPP::Base64Decoder::IsolatedInitialize(class CryptoPP::NameValuePairs const &)" (?IsolatedInitialize@Base64Decoder@CryptoPP@@UAEXABVNameValuePairs@2@@Z) ResultSheets C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj 1
Error LNK2001 unresolved external symbol "protected: virtual void __thiscall CryptoPP::EAX_Base::SetKeyWithoutResync(unsigned char const *,unsigned int,class CryptoPP::NameValuePairs const &)" (?SetKeyWithoutResync@EAX_Base@CryptoPP@@MAEXPBEIABVNameValuePairs@2@@Z) ResultSheets C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj 1
Error LNK2001 unresolved external symbol "protected: virtual void __thiscall CryptoPP::EAX_Base::Resync(unsigned char const *,unsigned int)" (?Resync@EAX_Base@CryptoPP@@MAEXPBEI@Z) ResultSheets C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj 1
Error LNK2001 unresolved external symbol "protected: virtual void __thiscall CryptoPP::EAX_Base::AuthenticateLastHeaderBlock(void)" (?AuthenticateLastHeaderBlock@EAX_Base@CryptoPP@@MAEXXZ) ResultSheets C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj 1
Error LNK2001 unresolved external symbol "protected: virtual unsigned int __thiscall CryptoPP::EAX_Base::AuthenticateBlocks(unsigned char const *,unsigned int)" (?AuthenticateBlocks@EAX_Base@CryptoPP@@MAEIPBEI@Z) ResultSheets C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj 1
Error LNK2019 unresolved external symbol "private: static int const * __cdecl CryptoPP::Base64Decoder::GetDecodingLookupArray(void)" (?GetDecodingLookupArray@Base64Decoder@CryptoPP@@CAPBHXZ) referenced in function "public: __thiscall CryptoPP::Base64Decoder::Base64Decoder(class CryptoPP::BufferedTransformation *)" (??0Base64Decoder@CryptoPP@@QAE@PAVBufferedTransformation@1@@Z) ResultSheets C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj 1
Error LNK2001 unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const CryptoPP::DEFAULT_CHANNEL" (?DEFAULT_CHANNEL@CryptoPP@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@B) ResultSheets C:\Users\HP\source\repos\ResultSheets\EncryptDecrypt.obj 1
Error LNK2019 unresolved external symbol "bool __cdecl Base64Encode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Base64Encode@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "int __stdcall SaveLicenceCode(struct HWND__ *,unsigned int,unsigned int,long)" (?SaveLicenceCode@@YGHPAUHWND__@@IIJ@Z) ResultSheets C:\Users\HP\source\repos\ResultSheets\ResultSheets.obj 1
Error LNK2019 unresolved external symbol "bool __cdecl Base64Decode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Base64Decode@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "bool __cdecl IsValidLicence(void)" (?IsValidLicence@@YA_NXZ) ResultSheets C:\Users\HP\source\repos\ResultSheets\LicenceFileData.obj 1
Error LNK2001 unresolved external symbol "bool __cdecl Base64Decode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?Base64Decode@@YA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) ResultSheets C:\Users\HP\source\repos\ResultSheets\ResultSheets.obj 1
Error LNK1120 11 unresolved externals ResultSheets C:\Users\HP\source\repos\ResultSheets\Debug\ResultSheets.exe 1
What I have tried:
Google search did not yield any useful result. The talked of missing .cpp files for LNK2001, but I have the dynamic library in place.I see no reason why a .cpp file should still be relevant when dealing with a dll.