In my application I am using encryption and decryption.
在我的应用程序中,我使用加密和解密。
Before entering the string in to local database, I am encrypting that and after fetching the data from database I am decrypting it and using in my application. It is working fine. I have used encryption/decryption from link below
在将字符串输入本地数据库之前,我正在对其进行加密,并且在从数据库获取数据之后,我正在解密它并在我的应用程序中使用。它工作正常。我在下面的链接中使用了加密/解密
At the time of Encrypting:
在加密时:
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];
At the time of Decrypting :
在Decrypting时:
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];
But I have made staticLibrary of that same project. I am using that staticLibrary in another project. When I run that project, at the time of encrypting it gave me error below
但我已经制作了同一个项目的staticLibrary。我在另一个项目中使用staticLibrary。当我运行该项目时,在加密时它给了我下面的错误
-[NSConcreteMutableData AESEncryptWithPassphrase:]: unrecognized selector sent to instance 0x6a3fe40
- [NSConcreteMutableData AESEncryptWithPassphrase:]:无法识别的选择器发送到实例0x6a3fe40
2 个解决方案
#1
0
You need to make change in the Build Settings of the project which will link the static library with the main project. Follow these steps:
您需要在项目的“构建设置”中进行更改,该项目将静态库与主项目链接起来。按着这些次序:
1)Click on Build Settings tab.
1)单击Build Settings选项卡。
2)Search for "Other Linker Flags".
2)搜索“其他链接标志”。
3)Add '-all_load' flag to it.
3)向其添加“-all_load”标志。
4)Build and run the project.
4)构建并运行项目。
It worked fine for me.
它对我来说很好。
#2
0
Did you import the category header file:
您是否导入了类别标题文件:
#import "NSData-AES.h"
I believe there is the AESDecryptWithPassphrase
method defined. Without that the app does not know about the method.
我相信定义了AESDecryptWithPassphrase方法。没有它,应用程序不知道该方法。
Just to clarify - you have to import the category header file to every file where you want to use the capabilities added by that category.
只是为了澄清 - 您必须将类别头文件导入到您要使用该类别添加的功能的每个文件。
#1
0
You need to make change in the Build Settings of the project which will link the static library with the main project. Follow these steps:
您需要在项目的“构建设置”中进行更改,该项目将静态库与主项目链接起来。按着这些次序:
1)Click on Build Settings tab.
1)单击Build Settings选项卡。
2)Search for "Other Linker Flags".
2)搜索“其他链接标志”。
3)Add '-all_load' flag to it.
3)向其添加“-all_load”标志。
4)Build and run the project.
4)构建并运行项目。
It worked fine for me.
它对我来说很好。
#2
0
Did you import the category header file:
您是否导入了类别标题文件:
#import "NSData-AES.h"
I believe there is the AESDecryptWithPassphrase
method defined. Without that the app does not know about the method.
我相信定义了AESDecryptWithPassphrase方法。没有它,应用程序不知道该方法。
Just to clarify - you have to import the category header file to every file where you want to use the capabilities added by that category.
只是为了澄清 - 您必须将类别头文件导入到您要使用该类别添加的功能的每个文件。