iOS应用程序在XCode上使用cryptopp静态库引发的异常4.6.2

问题描述:

下面是我的一些细节。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 
    
+0

你是如何构建libcryptopp.a? – gotomanners 2013-09-11 10:56:33

+0

你错过了很多信息,所以很难说。你能提供堆栈跟踪吗?否则,这是一个黑暗中的刺:你有一个全局的Crypto ++对象(静态存储)并使用默认通道。 DEFAULT_CHANNEL是一个std :: string,当对象使用它来命名通道时,该字符串尚未构造。 (它在所有操作系统上都存在不良行为,但Mac OS X对于跨平台单元的初始化尤其不利。 – jww 2013-10-02 04:54:11

+1

@gotomanners - 抱歉,延迟响应。我对cryto ++ makefiles做了一些修改。你可以在这里访问它们:https://github.com/nileshkaria/cryptopp 但是,请看下面的回复。我相信这可能是更好的解决方案。 – 2013-11-01 18:04:34

的加密++代码是好的。你的问题在别处。

不是试图交叉编译Crypto ++,也许你应该试试cryptopp-5.6.2-ios on GitHub。它有一个6.1 SDK的预建胖库(armv7,armv7s,i386);和一个7.0 SDK的预建胖库(armv7,armv7s,arm64,i386)。

Crypto++/iOS test code

+0

感谢您的回复并抱歉不早回复!我会试试看看它是如何发展的。 任何想法当上述步骤应用于现有项目时,我的代码是如何工作的? – 2013-11-01 18:01:25

+0

有没有人有Crypto ++的xcode5项目? – user1028028 2013-11-26 18:04:56

+0

user1028028 - 您应该开始一个新问题并解释您遇到问题的位置。 – jww 2013-11-27 09:16:26