Hi!
Trying to write program with encrypting lib - CryptoPP 7.0.0 (linking dll). This lib has itself operators new and delete.
#ifndef CRYPTOPP_DLL_ONLY
# define CRYPTOPP_DEFAULT_NO_DLL
#endif
#ifdef CRYPTOPP_IMPORTS
static CryptoPP::PNew s_pNew = NULLPTR;
static CryptoPP::PDelete s_pDelete = NULLPTR;
extern "C" __declspec(dllexport) void __cdecl SetNewAndDeleteFromCryptoPP(CryptoPP::PNew pNew, CryptoPP::PDelete pDelete, CryptoPP::PSetNewHandler pSetNewHandler)
{
(void)(pSetNewHandler);
s_pNew = pNew;
s_pDelete = pDelete;
}
void * __cdecl operator new (size_t size)
{
return s_pNew(size);
}
void __cdecl operator delete (void * p)
{
s_pDelete(p);
}
#endif
And because UE4 has itself overwrited operator new and delete i had a conflict:
LNK2005: bla bla bla already defined …
Without overwrite operators catch crash all program on the destructor.
Please help…
Example of using CryptoPP:
std::string AESApi::GetEncryptText(const std::string& text)
{
std::string outText;
try
{
CFB_Mode< AES >::Encryption e;
e.SetKeyWithIV((CryptoPP::byte*)Key.c_str(), Key.length(), (CryptoPP::byte*)Iv.c_str());
// CFB mode must not use padding. Specifying
// a scheme will result in an exception
StringSource(text, true, new StreamTransformationFilter(e, new StringSink(outText)));
}
catch (const CryptoPP::Exception& e)
{
std::cerr << e.what() << std::endl;
exit(1);
}
return outText;
}