Hi, it's me again...
I did manage to find the information on using both DLL as well as static
library but neither of them work when I try to do anything with RSA algorithm
:( I get errors when linking ;(
Here is my very short program that does nothing - it's really just a couple of
functions cut out from test.cpp:
********************************************************************************
#include "stdafx.h"
#include "dll.h"
#include "md5.h"
#include "ripemd.h"
#include "rng.h"
#include "gzip.h"
#include "default.h"
#include "randpool.h"
#include "ida.h"
#include "base64.h"
#include "socketft.h"
#include "wait.h"
#include "factory.h"
#include "validate.h"
#include "bench.h"
#include <iostream>
#include <time.h>
#ifdef CRYPTOPP_WIN32_AVAILABLE
#include <windows.h>
#endif
#if defined(USE_BERKELEY_STYLE_SOCKETS) && !defined(macintosh)
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
#if (_MSC_VER >= 1000)
#include <crtdbg.h> // for the debug heap
#endif
#if defined(__MWERKS__) && defined(macintosh)
#include <console.h>
#endif
USING_NAMESPACE(CryptoPP)
USING_NAMESPACE(std)
void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const
char *pubFilename, const char *seed);
string RSAEncryptString(const char *pubFilename, const char *seed, const char
*message);
string RSADecryptString(const char *privFilename, const char *ciphertext);
void GenerateRSAKey(unsigned int keyLength, const char *privFilename, const
char *pubFilename, const char *seed)
{
RandomPool randPool;
randPool.Put((byte *)seed, strlen(seed));
RSAES_OAEP_SHA_Decryptor priv(randPool, keyLength);
HexEncoder privFile(new FileSink(privFilename));
priv.DEREncode(privFile);
privFile.MessageEnd();
RSAES_OAEP_SHA_Encryptor pub(priv);
HexEncoder pubFile(new FileSink(pubFilename));
pub.DEREncode(pubFile);
pubFile.MessageEnd();
}
string RSAEncryptString(const char *pubFilename, const char *seed, const char
*message)
{
FileSource pubFile(pubFilename, true, new HexDecoder);
RSAES_OAEP_SHA_Encryptor pub(pubFile);
RandomPool randPool;
randPool.Put((byte *)seed, strlen(seed));
string result;
StringSource(message, true, new PK_EncryptorFilter(randPool, pub, new
HexEncoder(new StringSink(result))));
return result;
}
string RSADecryptString(const char *privFilename, const char *ciphertext)
{
FileSource privFile(privFilename, true, new HexDecoder);
RSAES_OAEP_SHA_Decryptor priv(privFile);
string result;
StringSource(ciphertext, true, new HexDecoder(new
PK_DecryptorFilter(GlobalRNG(), priv, new StringSink(result))));
return result;
}
********************************************************************************
When I try to bild it with a DLL I get this error:
********************************************************************************
Linking...
littleRSA.obj : error LNK2001: unresolved external symbol "class
CryptoPP::RandomPool & __cdecl GlobalRNG(void)" (?GlobalRNG@@[EMAIL
PROTECTED]@@XZ)
littleRSA.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: static class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > __cdecl
CryptoPP::RSA::StaticAlgorithmName(void)" (__imp_?StaticA
[EMAIL PROTECTED]@CryptoPP@@[EMAIL PROTECTED]@[EMAIL PROTECTED]@@[EMAIL
PROTECTED]@2@@std@@XZ)
littleRSA.obj : error LNK2001: unresolved external symbol
"__declspec(dllimport) public: static class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > __cdecl
CryptoPP::OAEP<class CryptoPP::SHA,class CryptoPP::P1363_
MGF1>::StaticAlgorithmName(void)" ([EMAIL PROTECTED]@[EMAIL PROTECTED]@@[EMAIL
PROTECTED]@@CryptoPP@@[EMAIL PROTECTED]@[EMAIL PROTECTED]@@[EMAIL
PROTECTED]@2@@std@@XZ)
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/littleRSA.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
littleRSA.exe - 5 error(s), 0 warning(s)
********************************************************************************
And when I try to build it with static library I get even more errors:
********************************************************************************
Linking...
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::RandomPool::~RandomPool(void)" ([EMAIL PROTECTED]@@[EMAIL PROTECTED])
already defined in cryptlib.lib(gf2n.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::HexEncoder::~HexEncoder(void)" ([EMAIL PROTECTED]@@[EMAIL PROTECTED])
already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: bool __thiscall
CryptoPP::BufferedTransformation::MessageEnd(int,bool)" ([EMAIL
PROTECTED]@CryptoPP@@[EMAIL PROTECTED]) already defined in
cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::HexEncoder::HexEncoder(class CryptoPP::BufferedTransformation
*,bool,int,class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > const &,class
std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>
> const &)" ([EMAIL PROTECTED]@@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL
PROTECTED]@std@@[EMAIL PROTECTED]@2@@std@@[EMAIL PROTECTED]) already defined in
cryptlib.
lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: unsigned int __thiscall
CryptoPP::BufferedTransformation::Put(unsigned char const *,unsigned int,bool)"
([EMAIL PROTECTED]@CryptoPP@@[EMAIL PROTECTED]) already defined in
cryptlib.lib(cryptli
b.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::RandomPool::RandomPool(unsigned int)" ([EMAIL PROTECTED]@@[EMAIL
PROTECTED]@Z) already defined in cryptlib.lib(randpool.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::FileSink::~FileSink(void)" ([EMAIL PROTECTED]@@[EMAIL PROTECTED])
already defined in cryptlib.lib(files.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::PK_CryptoSystem::~PK_CryptoSystem(void)" ([EMAIL PROTECTED]@@[EMAIL
PROTECTED]) already defined in cryptlib.lib(rsa.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: void __thiscall
CryptoPP::InvertibleRSAFunction::`vbase destructor'(void)" ([EMAIL
PROTECTED]@@QAEXXZ) already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: void __thiscall
CryptoPP::RSAFunction::`vbase destructor'(void)" ([EMAIL PROTECTED]@@QAEXXZ)
already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::TF_DecryptorBase::~TF_DecryptorBase(void)" ([EMAIL PROTECTED]@@[EMAIL
PROTECTED]) already defined in cryptlib.lib(rsa.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::TF_EncryptorBase::~TF_EncryptorBase(void)" ([EMAIL PROTECTED]@@[EMAIL
PROTECTED]) already defined in cryptlib.lib(rsa.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::FileSource::~FileSource(void)" ([EMAIL PROTECTED]@@[EMAIL PROTECTED])
already defined in cryptlib.lib(files.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::StringSource::~StringSource(void)" ([EMAIL PROTECTED]@@[EMAIL
PROTECTED]) already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::StringSource::StringSource(char const *,bool,class
CryptoPP::BufferedTransformation *)" ([EMAIL PROTECTED]@@[EMAIL
PROTECTED]@1@@Z) already defined in
cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::PK_EncryptorFilter::PK_EncryptorFilter(class
CryptoPP::RandomNumberGenerator &,class CryptoPP::PK_Encryptor const &,class
CryptoPP::BufferedTransformation *)" (??0PK_Encryptor
[EMAIL PROTECTED]@@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@1@@Z)
already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::StringSinkTemplate<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > >::StringSinkTemplate<class
std::basic_string<char,struct std::char_
traits<char>,class std::allocator<char> > >(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > &)" ([EMAIL
PROTECTED]@[EMAIL PROTECTED]@std@@[EMAIL PROTECTED]@2@@std@@@CryptoPP@@[EMAIL
PROTECTED]
[EMAIL PROTECTED]@[EMAIL PROTECTED]@@[EMAIL PROTECTED]@2@@std@@@Z) already
defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::HexDecoder::HexDecoder(class CryptoPP::BufferedTransformation *)"
([EMAIL PROTECTED]@@[EMAIL PROTECTED]@1@@Z) already defined in
cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::PK_EncryptorFilter::~PK_EncryptorFilter(void)" ([EMAIL
PROTECTED]@@[EMAIL PROTECTED]) already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::HexDecoder::~HexDecoder(void)" ([EMAIL PROTECTED]@@[EMAIL PROTECTED])
already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::StringSinkTemplate<class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >
>::~StringSinkTemplate<class std::basic_string<char,struct s
td::char_traits<char>,class std::allocator<char> > >(void)" ([EMAIL
PROTECTED]@[EMAIL PROTECTED]@std@@[EMAIL PROTECTED]@2@@std@@@CryptoPP@@[EMAIL
PROTECTED]) already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::PK_DecryptorFilter::PK_DecryptorFilter(class
CryptoPP::RandomNumberGenerator &,class CryptoPP::PK_Decryptor const &,class
CryptoPP::BufferedTransformation *)" (??0PK_Decryptor
[EMAIL PROTECTED]@@[EMAIL PROTECTED]@[EMAIL PROTECTED]@[EMAIL PROTECTED]@1@@Z)
already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::PK_DecryptorFilter::~PK_DecryptorFilter(void)" ([EMAIL
PROTECTED]@@[EMAIL PROTECTED]) already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::CannotFlush::CannotFlush(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > const &)" ([EMAIL
PROTECTED]@@[EMAIL PROTECTED]@DU?$
[EMAIL PROTECTED]@std@@[EMAIL PROTECTED]@2@@std@@@Z) already defined in
cryptlib.lib(cryptlib.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::PK_CryptoSystem::PK_CryptoSystem(void)" ([EMAIL PROTECTED]@@[EMAIL
PROTECTED]) already defined in cryptlib.lib(rsa.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: class
CryptoPP::InvertibleRSAFunction & __thiscall
CryptoPP::InvertibleRSAFunction::operator=(class
CryptoPP::InvertibleRSAFunction const &)" ([EMAIL PROTECTED]@@[EMAIL
PROTECTED]@@Z)
already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: class
CryptoPP::RSAFunction & __thiscall CryptoPP::RSAFunction::operator=(class
CryptoPP::RSAFunction const &)" ([EMAIL PROTECTED]@@[EMAIL PROTECTED]@@Z)
already defined in cryptlib.lib(fipstes
t.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::InvertibleRSAFunction::InvertibleRSAFunction(void)" ([EMAIL
PROTECTED]@@[EMAIL PROTECTED]) already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::RSAFunction::RSAFunction(void)" ([EMAIL PROTECTED]@@[EMAIL
PROTECTED]) already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::TF_DecryptorBase::TF_DecryptorBase(void)" ([EMAIL PROTECTED]@@[EMAIL
PROTECTED]) already defined in cryptlib.lib(rsa.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::TF_EncryptorBase::TF_EncryptorBase(void)" ([EMAIL PROTECTED]@@[EMAIL
PROTECTED]) already defined in cryptlib.lib(rsa.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::Integer::~Integer(void)" ([EMAIL PROTECTED]@@[EMAIL PROTECTED])
already defined in cryptlib.lib(fipstest.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: void __thiscall
CryptoPP::InvertibleRSAFunction::Initialize(class
CryptoPP::RandomNumberGenerator &,unsigned int,class CryptoPP::Integer const
&)" ([EMAIL PROTECTED]@CryptoPP@@QAEX
[EMAIL PROTECTED]@[EMAIL PROTECTED]@@Z) already defined in cryptlib.lib(rsa.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::Integer::Integer(long)" ([EMAIL PROTECTED]@@[EMAIL PROTECTED]@Z)
already defined in cryptlib.lib(integer.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: __thiscall
CryptoPP::OAEP<class CryptoPP::SHA,class CryptoPP::P1363_MGF1>::OAEP<class
CryptoPP::SHA,class CryptoPP::P1363_MGF1>(void)" ([EMAIL
PROTECTED]@CryptoPP@@[EMAIL PROTECTED]@@CryptoPP@@[EMAIL PROTECTED]) al
ready defined in cryptlib.lib(rsa.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: virtual __thiscall
CryptoPP::OAEP<class CryptoPP::SHA,class CryptoPP::P1363_MGF1>::~OAEP<class
CryptoPP::SHA,class CryptoPP::P1363_MGF1>(void)" ([EMAIL
PROTECTED]@CryptoPP@@[EMAIL PROTECTED]@@CryptoPP@@U
[EMAIL PROTECTED]) already defined in cryptlib.lib(rsa.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: unsigned int __thiscall
CryptoPP::Integer::ByteCount(void)const " ([EMAIL PROTECTED]@CryptoPP@@QBEIXZ)
already defined in cryptlib.lib(integer.obj)
cryptopp.lib(cryptopp.dll) : error LNK2005: "public: unsigned int __thiscall
CryptoPP::Integer::BitCount(void)const " ([EMAIL PROTECTED]@CryptoPP@@QBEIXZ)
already defined in cryptlib.lib(integer.obj)
LIBCMTD.lib(_file.obj) : error LNK2005: ___initstdio already defined in
LIBCD.lib(_file.obj)
LIBCMTD.lib(_file.obj) : error LNK2005: ___endstdio already defined in
LIBCD.lib(_file.obj)
LIBCMTD.lib(_file.obj) : error LNK2005: __cflush already defined in
LIBCD.lib(_file.obj)
LIBCMTD.lib(_file.obj) : error LNK2005: __iob already defined in
LIBCD.lib(_file.obj)
LIBCMTD.lib(dosmap.obj) : error LNK2005: __dosmaperr already defined in
LIBCD.lib(dosmap.obj)
LIBCMTD.lib(tolower.obj) : error LNK2005: __tolower already defined in
LIBCD.lib(tolower.obj)
LIBCMTD.lib(tolower.obj) : error LNK2005: _tolower already defined in
LIBCD.lib(tolower.obj)
LIBCMTD.lib(read.obj) : error LNK2005: __read already defined in
LIBCD.lib(read.obj)
LIBCMTD.lib(lseek.obj) : error LNK2005: __lseek already defined in
LIBCD.lib(lseek.obj)
LIBCMTD.lib(osfinfo.obj) : error LNK2005: __alloc_osfhnd already defined in
LIBCD.lib(osfinfo.obj)
LIBCMTD.lib(osfinfo.obj) : error LNK2005: __set_osfhnd already defined in
LIBCD.lib(osfinfo.obj)
LIBCMTD.lib(osfinfo.obj) : error LNK2005: __free_osfhnd already defined in
LIBCD.lib(osfinfo.obj)
LIBCMTD.lib(osfinfo.obj) : error LNK2005: __get_osfhandle already defined in
LIBCD.lib(osfinfo.obj)
LIBCMTD.lib(osfinfo.obj) : error LNK2005: __open_osfhandle already defined in
LIBCD.lib(osfinfo.obj)
LIBCMTD.lib(write.obj) : error LNK2005: __write already defined in
LIBCD.lib(write.obj)
LINK : warning LNK4098: defaultlib "LIBCMTD" conflicts with use of other libs;
use /NODEFAULTLIB:library
LINK : warning LNK4049: locally defined symbol ""public: static class
std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>
> __cdecl CryptoPP::RSA::StaticAlgorithmName(void)" ([EMAIL
PROTECTED]@CryptoPP@@SA?AV?$basi
[EMAIL PROTECTED]@[EMAIL PROTECTED]@@[EMAIL PROTECTED]@2@@std@@XZ)" imported
LINK : warning LNK4049: locally defined symbol ""public: static class
std::basic_string<char,struct std::char_traits<char>,class std::allocator<char>
> __cdecl CryptoPP::OAEP<class CryptoPP::SHA,class
CryptoPP::P1363_MGF1>::StaticAlgorithmName(void)
" ([EMAIL PROTECTED]@[EMAIL PROTECTED]@@[EMAIL PROTECTED]@@CryptoPP@@[EMAIL
PROTECTED]@[EMAIL PROTECTED]@@[EMAIL PROTECTED]@2@@std@@XZ)" imported
littleRSA.obj : error LNK2001: unresolved external symbol "class
CryptoPP::RandomPool & __cdecl GlobalRNG(void)" (?GlobalRNG@@[EMAIL
PROTECTED]@@XZ)
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/littleRSA.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
littleRSA.exe - 56 error(s), 3 warning(s)
********************************************************************************
I'm sorry for the lenghty post.
What am I doing wrong? What should I do? Please, I really need help :(
I've tried using the latest source from CVS but it doesn't compile :|
Best regards,
Crocodil