下面是我的一些細節。iOS應用程序在XCode上使用cryptopp靜態庫引發的異常4.6.2
- 單獨編譯的crypto ++版本,並有一個靜態庫(libcryptopp.a)。
- 創建示例單視圖應用程序並鏈接上述庫,創建新組以包含crypto ++標頭。這些標題不會被複制到應用程序的目標文件夾中。
在應用程序中創建一個新的.mm文件,我正在執行一些示例代碼,我現在要發送到控制檯。請注意,此示例代碼與測試文件SymmetricCipher.cpp中提供的示例代碼幾乎沒有修改。
設置下的項目構建設置:
蘋果LLVM編譯器4.2設置
- C語言的方言 - GNU99
- C++語言的方言 - GNU ++ 11
C++標準庫 - libstdC++
對現有項目進行完全相同的更改,並在現有文件中插入示例代碼以測試輸出。這工作沒有任何問題。
代碼在獨立的應用程序拋出異常「EXC_BAD_ACCESS(代碼= 2,地址爲0x20 =)」
#import "TestView.h" //Include C++ headers #ifdef __cplusplus #include "aes.h" // Includes all required Crypto++ // Block Cipher Headers #include "SymmetricCipher.h" #include <iostream> #include <iomanip> // Crypto++ Includes #include "modes.h" // xxx_Mode< > #include "filters.h" // StringSource and // StreamTransformation #include "sha.h" #include "base64.h" #endif @implementation TestView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } - (void)testBlock { //Test code byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ]; ::memset(key, 0x01, CryptoPP::AES::DEFAULT_KEYLENGTH); ::memset(iv, 0x01, CryptoPP::AES::BLOCKSIZE); // Message M std::string PlainText = "Yoda said,Do or Do Not. There is no try."; // Cipher Text Sink std::string CipherText; // Encryptor CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption Encryptor(key, sizeof(key), iv); // Encryption CryptoPP::StringSource(PlainText, true, new CryptoPP::StreamTransformationFilter(Encryptor, new CryptoPP::StringSink(CipherText)) // StreamTransformationFilter ); // StringSource // example of hashing followed by base64 encoding, using filters std::string digest; CryptoPP::SHA256 hash; // don't use MD5 anymore. It is considered insecure CryptoPP::StringSource foo(PlainText, true, new CryptoPP::HashFilter(hash, new CryptoPP::Base64Encoder (new CryptoPP::StringSink(digest)))); NSLog(@"SHA256 Hash %s", digest.c_str()); } @end
你是如何構建libcryptopp.a? – gotomanners 2013-09-11 10:56:33
你錯過了很多信息,所以很難說。你能提供堆棧跟蹤嗎?否則,這是一個黑暗中的刺:你有一個全局的Crypto ++對象(靜態存儲)並使用默認通道。 DEFAULT_CHANNEL是一個std :: string,當對象使用它來命名通道時,該字符串尚未構造。 (它在所有操作系統上都存在不良行爲,但Mac OS X對於跨平臺單元的初始化尤其不利。 – jww 2013-10-02 04:54:11
@gotomanners - 抱歉,延遲響應。我對cryto ++ makefiles做了一些修改。你可以在這裏訪問它們:https://github.com/nileshkaria/cryptopp 但是,請看下面的回覆。我相信這可能是更好的解決方案。 – 2013-11-01 18:04:34