我已成功为iPhone模拟器创建了OpenSSL库。我已成功导入所有标头和库。但是,我在构建项目时遇到问题,XCode告诉我结构X509_ALGOR 的不完整定义。这是代码:
- (NSData *)encodePBEWithMD5AndDESData:(NSData *)inData password:(NSString *)password direction:(int)direction
{
// Change salt and number of iterations for your project !!!
static const char gSalt[] =
{
(unsigned char)0xaa, (unsigned char)0xd1, (unsigned char)0x3c, (unsigned char)0x31,
(unsigned char)0x53, (unsigned char)0xa2, (unsigned char)0xee, (unsigned char)0x05
};
unsigned char *salt = (unsigned char *)gSalt;
int saltLen = strlen(gSalt);
int iterations = 15;
EVP_CIPHER_CTX cipherCtx;
unsigned char *mResults; // allocated storage of results
int mResultsLen = 0;
const char *cPassword = [password UTF8String];
unsigned char *mData = (unsigned char *)[inData bytes];
int mDataLen = [inData length];
SSLeay_add_all_algorithms();
X509_ALGOR *algorithm = PKCS5_pbe_set(NID_pbeWithMD5AndDES_CBC,
iterations, salt, saltLen);
memset(&cipherCtx, 0, sizeof(cipherCtx));
if (algorithm != NULL)
{
EVP_CIPHER_CTX_init(&(cipherCtx));
**if (EVP_PBE_CipherInit(algorithm->algorithm, cPassword, strlen(cPassword),
algorithm->parameter, &(cipherCtx), direction))**
{
EVP_CIPHER_CTX_set_padding(&cipherCtx, 1);
int blockSize = EVP_CIPHER_CTX_block_size(&cipherCtx);
int allocLen = mDataLen + blockSize + 1; // plus 1 for null terminator on decrypt
mResults = (unsigned char *)OPENSSL_malloc(allocLen);
unsigned char *in_bytes = mData;
int inLen = mDataLen;
unsigned char *out_bytes = mResults;
int outLen = 0;
发现未完全定义了结构X509_ALGOR的指针,即“算法”。我对此没有任何线索。有人可以帮帮我吗?
if (EVP_PBE_CipherInit(algorithm->algorithm, cPassword, strlen(cPassword),
algorithm->parameter, &(cipherCtx), direction))
答案 0 :(得分:0)
我不确定是否适合回答我自己的问题。但是,如果有人遇到同样的问题我会这样做,他/她可能会得到一些帮助。
上面提到的代码的问题是链接器标志。在“Build Settings”下的“Other Linker Flags”中设置“-ObjC -load_all”后,问题就消失了。
问候。