dear all i made a code for sign some data and verify it i am using eclipse as IDE and ubuntu 13.10 i have linked eclipse with ssl lib and crypto++ which i use in this code i got an error
Invoking: Cross G++ Linker g++ -L/usr/include/openssl -L/usr/include/cryptopp -L/usr/include/crypto++ -L/usr/include -o "sign" ./src/sign.o -lssl -lcryptopp -lcrypto++ /usr/bin/ld: ./src/sign.o: undefined reference to symbol 'RSA_sign@ @OPENSSL_1.0.0' /lib/i386-linux-gnu/libcrypto.so.1.0.0: error adding symbols: DSO missing from command line collect2: ld returned 1 exit status what can i do i need real help -- Warmest regards and best wishes for a good health,*urs sincerely * *mero*
/* * sign.cc * * Created on: Oct 30, 2014 * Author: amir */ #include "sign.h" Sign::Sign() { m_rsa_keyPairs = RSA_new(); GenerateRSAPairs(); SetSharedKey(); } Sign::~Sign() { RSA_free(m_rsa_keyPairs); } void Sign::SetANData(int size) { cout<<"andata is "<<endl; for (int i = 0 ; i<size ; i++) { m_ANdata[i]=i; cout<<m_ANdata[i]; } } void Sign::SetGSData(int size,int sharedsize) { cout<<"gsdata is "<<endl; sharedsize = CryptoPP::AES::DEFAULT_KEYLENGTH; int totalsize = size +sharedsize; for (int i = 0 ; i<size ; i++) { m_GSdata[i]=i; cout<<m_GSdata[i]; } for (int j = size ; j<totalsize ; j++) { m_GSdata[j]=m_sharedKey[j]; cout<<m_GSdata[j]; } } void Sign::SetSharedKey() { CryptoPP::AutoSeededRandomPool prng; prng.GenerateBlock( m_sharedKey, CryptoPP::AES::DEFAULT_KEYLENGTH); } void Sign::EncryptSharedKey() { int padding = RSA_PKCS1_PADDING; RSA_public_encrypt(CryptoPP::AES::DEFAULT_KEYLENGTH,m_sharedKey,m_encryptedSharedKey,m_rsa_keyPairs,padding); } void Sign::DecryptSharedKey() { int padding = RSA_PKCS1_PADDING; RSA_private_decrypt(RSA_size(m_rsa_keyPairs),m_encryptedSharedKey,m_sharedKey,m_rsa_keyPairs,padding); } void Sign::SignData(unsigned char *signeddata , const unsigned char *datatobesigned , unsigned int m_len , unsigned int *siglen) { RSA_sign(NID_sha1, datatobesigned, m_len, signeddata, siglen, m_rsa_keyPairs); cout<<"sign length is "<<siglen<<endl; } bool Sign::VerifySign(const unsigned char *signeddata , const unsigned char *datatobesigned , unsigned int m_len , unsigned int siglen) { int status = 0; status = RSA_verify(NID_sha1, datatobesigned, m_len, signeddata, siglen,m_rsa_keyPairs); if (status == 1) { return true; cout<<"verification is ok"<<endl; } else { return false; cout<<"verification fail"<<endl; } return false; } void Sign::GenerateRSAPairs() { m_rsa_keyPairs = RSA_generate_key(2048,RSA_F4,NULL,NULL); }
//============================================================================ // Name : sign.cpp // Author : Amir // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include "sign.h" using namespace std; int main() { Sign test; test.SetANData(16); test.SetGSData(16,CryptoPP::AES::DEFAULT_KEYLENGTH); test.SignData(m_ANdata,m_ANsignData,16,256); test.VerifySign(m_ANdata,m_ANsignData,16,256); return 0; }
/* * sign.h * * Created on: Oct 30, 2014 * Author: amir */ #ifndef SIGN_H_ #define SIGN_H_ #include <iostream> #include <openssl/rsa.h> #include <openssl/pem.h> #include <openssl/conf.h> #include <cryptopp/config.h> #include <cryptopp/aes.h> #include <cryptopp/osrng.h> #include <cryptopp/hex.h> #include <cryptopp/cryptlib.h> #include <cryptopp/filters.h> #include <stdlib.h> #include <stdio.h> using namespace std; class Sign { public: Sign(); ~Sign(); void SetANData(int size); void SetGSData(int size,int sharedsize); void SetSharedKey(); void GenerateRSAPairs(); void EncryptSharedKey(); void DecryptSharedKey(); void SignData(unsigned char *signeddata , const unsigned char *datatobesigned , unsigned int m_len , unsigned int *siglen); bool VerifySign(const unsigned char *signeddata , const unsigned char *datatobesigned , unsigned int m_len , unsigned int siglen); private: RSA *m_rsa_keyPairs; byte m_sharedKey[CryptoPP::AES::DEFAULT_KEYLENGTH]; unsigned char m_ANdata[16]; unsigned char m_GSdata[CryptoPP::AES::DEFAULT_KEYLENGTH + 16]; unsigned char m_ANsignData [256]; unsigned char m_GSsignData [256]; unsigned char m_encryptedSharedKey [2048]; }; #endif /* SIGN_H_ */