在我的应用程序中,我使用了加密和解密。
在将字符串输入到本地数据库之前,我对其进行加密,在从数据库中获取数据后,我对其进行解密并在我的应用程序中使用。 它工作正常。我使用了来自的加密/解密 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:]: unrecognized selector sent to instance 0x6a3fe40
最佳答案
您需要更改项目的build设置,将静态库链接到主项目。 请按照以下步骤操作:
1) 单击build设置选项卡。
2)搜索“其他链接器标志”。
3) 添加'-all_load'标志。
4)构建并运行项目。
它对我来说效果很好。
关于ios - 在 staticLibrary 中加密字符串时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10384170/