加密++ AES代码和链接上的未定义符号

时间:2018-06-11 06:47:03

标签: c++ debian crypto++

我正在尝试构建一个cryptopp加密器(Encryptop.cpp类)。在我的代码下面:

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdexcept>

#include "cryptlib.h"
#include "modes.h"
#include "aes.h"
#include "filters.h"

#if defined(CRYPTOPP_NO_GLOBAL_BYTE)
  using CryptoPP::byte;
#endif

namespace common {

    Encryptor::Encryptor() {}
    Encryptor::~Encryptor() {}

    std::string Encryptor::encrypt(std::string text)
    {
        byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ];
        memset( key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH );
        memset( iv, 0x00, CryptoPP::AES::BLOCKSIZE );

        std::string ciphertext;

        CryptoPP::AES::Encryption aesEncryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
        CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption( aesEncryption, iv );

        CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink( ciphertext ) );
        stfEncryptor.Put( reinterpret_cast<const unsigned char*>( text.c_str() ), text.length() + 1 );
        stfEncryptor.MessageEnd();

        return ciphertext;
    }

    std::string Encryptor::decrypt(std::string ciphertext)
    {
        byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ];
        memset( key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH );
        memset( iv, 0x00, CryptoPP::AES::BLOCKSIZE );

        CryptoPP::AES::Decryption aesDecryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
        CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv );

        std::string decryptedtext;

        CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink( decryptedtext ) );
        stfDecryptor.Put( reinterpret_cast<const unsigned char*>( ciphertext.c_str() ), ciphertext.size() );
        stfDecryptor.MessageEnd();

        return decryptedtext;

    }
}

链接时我得到以下未定义的符号:

/home/myself/dev/common/lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::BlockCipherFinal<(CryptoPP::CipherDir)0, CryptoPP::Rijndael::Enc>::BlockCipherFinal(unsigned char const*, unsigned long)':
Encryptor.cpp:(.text._ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEC2EPKhm[_ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE0ENS_8Rijndael3EncEEC5EPKhm]+0x3b): undefined reference to `CryptoPP::g_nullNameValuePairs'
/home/myself/dev/common/lib/libcommon.a(Encryptor.cpp.o): In function `CryptoPP::BlockCipherFinal<(CryptoPP::CipherDir)1, CryptoPP::Rijndael::Dec>::BlockCipherFinal(unsigned char const*, unsigned long)':
Encryptor.cpp:(.text._ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEC2EPKhm[_ZN8CryptoPP16BlockCipherFinalILNS_9CipherDirE1ENS_8Rijndael3DecEEC5EPKhm]+0x3b): undefined reference to `CryptoPP::g_nullNameValuePairs'
/home/myself/dev/common/lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP12CBC_ModeBaseE[_ZTVN8CryptoPP12CBC_ModeBaseE]+0x128): undefined reference to `CryptoPP::StreamTransformation::ProcessLastBlock(unsigned char*, unsigned char const*, unsigned long)'
/home/myself/dev/common/lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP14CipherModeBaseE[_ZTVN8CryptoPP14CipherModeBaseE]+0x100): undefined reference to `CryptoPP::StreamTransformation::ProcessLastBlock(unsigned char*, unsigned char const*, unsigned long)'
/home/myself/dev/common/lib/libcommon.a(Encryptor.cpp.o):(.rodata._ZTVN8CryptoPP15SymmetricCipherE[_ZTVN8CryptoPP15SymmetricCipherE]+0xe8): undefined reference to `CryptoPP::StreamTransformation::ProcessLastBlock(unsigned char*, unsigned char const*, unsigned long)'

我是否遗漏了其他任何库(我目前正在链接到libcryptpp),或者是否缺少任何包含文件?

编辑: 已安装的Cryptopp版本:

$ dpkg-query -l | grep libcrypto
ii  libcrypto++-dev                5.6.1-6+deb8u3                     amd64        General purpose cryptographic library - C++ development
ii  libcrypto++-doc                5.6.1-6+deb8u3                     all          General purpose cryptographic library - documentation
ii  libcrypto++-utils              5.6.1-6+deb8u3                     amd64        General purpose cryptographic library - utilities and data files
ii  libcrypto++9                   5.6.1-6+deb8u3                     amd64        General purpose cryptographic library - shared library
ii  libcrypto++9-dbg               5.6.1-6+deb8u3                     amd64        General purpose cryptographic library - debug symbols
ii  libcryptokit-ocaml             1.9-2                              amd64        cryptographic algorithm library for OCaml - runtime
ii  libcryptokit-ocaml-dev         1.9-2                              amd64        cryptographic algorithm library for OCaml - development

0 个答案:

没有答案