【问题标题】:Error while encrypting string in staticLibrary在 staticLibrary 中加密字符串时出错
【发布时间】:2012-05-10 04:21:15
【问题描述】:

在我的应用程序中,我使用加密和解密。

在将字符串输入到本地数据库之前,我对其进行加密,从数据库中获取数据后,我将对其进行解密并在我的应用程序中使用。 它工作正常。我使用了加密/解密 link below

加密时:

    NSString *myKey=@"any string more than 8 char";

    NSData *data ; 
    NSData *encryptedData; 
    NSString *encryptPassword,*encryptPasscode;

    // 1) Encrypt

    data = [password dataUsingEncoding: NSASCIIStringEncoding];
    encryptedData = [data AESEncryptWithPassphrase:myKey];

    // 2) Encode Base 64

    [Base64 initialize];
    encryptPassword = [Base64 encode:encryptedData];

解密时:

    NSData *decryptedData;
    NSData  *b64DecData;

    field1 = (char *) sqlite3_column_text(selectPasscodeStatement, 0);
    NSString *fieldStr1 = [[NSString alloc] initWithUTF8String: field1];

     // 3) Decode Base 64

      b64DecData = [Base64 decode:fieldStr1];

     // 4) Decrypt

       decryptedData = [b64DecData AESDecryptWithPassphrase:myKey];

       retrivedPasscode = [[NSString alloc] initWithData:decryptedData encoding:NSASCIIStringEncoding];

但我已经为同一个项目制作了 staticLibrary。我在另一个项目中使用那个 staticLibrary。当我运行该项目时,在加密时它给了我下面的错误

-[NSConcreteMutableData AESEncryptWithPassphrase:]:无法识别的选择器发送到实例 0x6a3fe40

【问题讨论】:

    标签: ios ios5 encryption ios4 ios-simulator


    【解决方案1】:

    你是否导入了分类头文件:

    #import "NSData-AES.h"
    

    我相信已经定义了AESDecryptWithPassphrase 方法。否则,应用程序不知道该方法。

    澄清一下 - 您必须将类别头文件导入到要使用该类别添加的功能的每个文件中。

    【讨论】:

    • -> 是的,我在 staticLibrary 和当前项目中都包含了#import "NSData-AES.h"。我不知道它是如何调用 [NSConcreteMutableData AESEncryptWithPassphrase:] 函数的
    【解决方案2】:

    您需要在项目的构建设置中进行更改,它将静态库与主项目链接。 请按以下步骤操作:

    1)单击构建设置选项卡。

    2) 搜索“其他链接器标志”。

    3) 为其添加“-all_load”标志。

    4)构建并运行项目。

    对我来说效果很好。

    【讨论】:

      猜你喜欢
      • 2014-11-24
      • 1970-01-01
      • 2018-08-30
      • 2020-03-20
      • 1970-01-01
      • 1970-01-01
      • 2022-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多