0

以下代码不适用于设备它不会进入设备上的 while 循环,但它在模拟器上运行。

int status;
char value[1024] = "abcd";
FILE *fp = popen("openssl enc -aes-128-cbc -k secret -P -md sha1 2>&1", "r");
if (fp == NULL)
    exit(1); // handle error
int i=0;
NSString *strAESKey;
while (fgets(value, 1024, fp) != NULL)
{
    i++;
    if(i==2)
    {
        strAESKey=[NSString stringWithFormat:@"%s",value];
        break;
    }
}

status = pclose(fp);
if (status == -1)
{
    /* Error reported by pclose() */
}
else
{
    /* Use macros described under wait() to inspect `status' in order
                         to determine success/failure of command executed by popen() */
}

我哪里错了?

4

1 回答 1

4

iOS 应用程序沙箱禁止使用该fork函数,该函数popen使用。模拟器不使用沙箱,但设备使用。

您将需要直接使用 openssl 库,而不是使用命令行程序。iOS 公共 API 不包含 openssl 库,因此您需要自己构建一个静态库。您可以通过搜索找到一些帮助。我将从这篇博文开始。

于 2013-02-11T07:36:19.583 回答