2016-12-04 40 views
-1

我想編譯一個AES代碼,但是當我嘗試這樣做時出現錯誤。下面的代碼給出:丟失的符號Rijndael :: Enc :: ProcessAndXorBlock和Rijndael :: Dec :: ProcessAndXorBlock

#include <iostream> 
#include <iomanip> 

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

int main(int argc, char* argv[]) { 

//Key and IV setup 
//AES encryption uses a secret key of a variable length (128-bit, 196-bit or 256- 
//bit). This key is secretly exchanged between two parties before communication 
//begins. DEFAULT_KEYLENGTH= 16 bytes 
byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ]; 
memset(key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH); 
memset(iv, 0x00, CryptoPP::AES::BLOCKSIZE); 

// 
// String and Sink setup 
// 
std::string plaintext = "Now is the time for all good men to come to the aide..."; 
std::string ciphertext; 
std::string decryptedtext; 

// 
// Dump Plain Text 
// 
std::cout << "Plain Text (" << plaintext.size() << " bytes)" << std::endl; 
std::cout << plaintext; 
std::cout << std::endl << std::endl; 

// 
// Create Cipher Text 
// 
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*>(plaintext.c_str()), plaintext.length() + 1); 
stfEncryptor.MessageEnd(); 

// 
// Dump Cipher Text 
// 
std::cout << "Cipher Text (" << ciphertext.size() << " bytes)" << std::endl; 

for(int i = 0; i < ciphertext.size(); i++) { 

    std::cout << "0x" << std::hex << (0xFF & static_cast<byte>(ciphertext[i])) << " "; 
} 

std::cout << std::endl << std::endl; 

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

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

// 
// Dump Decrypted Text 
// 
std::cout << "Decrypted Text: " << std::endl; 
std::cout << decryptedtext; 
std::cout << std::endl << std::endl; 

return 0; 
} 

我得到下面給出的錯誤,這只是一個小樣本,有很多更但是這一切似乎與此類似:

"non-virtual thunk to CryptoPP::Rijndael::Enc::ProcessAndXorBlock(unsigned char const*, unsigned char const*, unsigned char*) const", referenced from: 
     vtable for CryptoPP::BlockCipherFinal<(CryptoPP::CipherDir)0, CryptoPP::Rijndael::Enc> in project-53b621.o 
     vtable for CryptoPP::ClonableImpl<CryptoPP::BlockCipherFinal<(CryptoPP::CipherDir)0, CryptoPP::Rijndael::Enc>, CryptoPP::Rijndael::Enc> in project-53b621.o 
    "non-virtual thunk to CryptoPP::Rijndael::Enc::AdvancedProcessBlocks(unsigned char const*, unsigned char const*, unsigned char*, unsigned long, unsigned int) const", referenced from: 
     vtable for CryptoPP::BlockCipherFinal<(CryptoPP::CipherDir)0, CryptoPP::Rijndael::Enc> in project-53b621.o 
     vtable for CryptoPP::ClonableImpl<CryptoPP::BlockCipherFinal<(CryptoPP::CipherDir)0, CryptoPP::Rijndael::Enc>, CryptoPP::Rijndael::Enc> in project-53b621.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

我我不確定問題是什麼,我到處尋找解決辦法,但我沒有找到任何可行的方法。任何意見,將不勝感激。

+0

要弄清楚如何解決此問題,我們需要更多信息,如平臺詳細信息和編譯/鏈接命令。從臀部拍攝,這聽起來像你*不*鏈接到'libcryptopp.a'。或者在編譯/鏈接命令中庫存在錯誤的位置。另請參見[如何鏈接到C中的靜態庫?](http://stackoverflow.com/q/1705961)Crypto ++有一個類似的報告位於[問題283:鏈接失敗,庫和程序功能不匹配](https: //github.com/weidai11/cryptopp/issues/283)。這是由於ABI休息,但我不相信它適用於你。 – jww

回答

0

您是否嘗試過製作標題#include "cryptopp/modes.h"等?我不確定你的計算機上安裝了Crypto ++,但這可能是問題,因爲它是一個鏈接器問題。確保你用-lcryptopp編譯。看看你如何鏈接你的對象文件。解釋如何以及在哪裏安裝了cryptopp。發佈有關該信息的更多信息

+0

當我在#include「cryptopp/modes.h」中添加它時出現錯誤 – Dylan

+0

我更新了答案以詢問更多信息 –