0

我已经成功地为 iPhone 模拟器创建了 OpenSSL 库。我已经成功导入了所有的头文件和库。但是,我在构建项目时遇到问题,XCode 告诉我struct 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;

发现指向 struct X509_ALGOR 的指针(即“算法”)未完全定义。我对此一无所知。任何人都可以帮助我吗?

if (EVP_PBE_CipherInit(algorithm->algorithm, cPassword, strlen(cPassword),
                           algorithm->parameter, &(cipherCtx), direction))
4

1 回答 1

0

我不确定是否适合发布我自己的问题的答案。但是,如果有人有同样的问题,我会这样做,他/她可能会从中得到一些帮助。

上述代码的问题在于链接器标志。一旦我在“构建设置”下的“其他链接器标志”中设置“-ObjC -load_all”,问题就消失了。

问候。

于 2012-07-14T05:11:04.487 回答