在staticLibrary中加密字符串时出错

时间:2012-04-30 13:02:06

标签: ios ios5 encryption ios4 ios-simulator

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

在将字符串输入本地数据库之前,我正在对其进行加密,并且在从数据库获取数据之后,我正在解密它并在我的应用程序中使用。 它工作正常。我使用过加密/解密 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

2 个答案:

答案 0 :(得分:0)

您是否导入了类别标题文件:

#import "NSData-AES.h"

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

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

答案 1 :(得分:0)

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

1)单击Build Settings选项卡。

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

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

4)构建并运行项目。

它对我来说很好。