【发布时间】:2020-12-14 22:36:17
【问题描述】:
我编写了下面的代码 sn-p,它通过 echo'ing 将字符串传递给 openssl,使用 popen;但是结果与我在 PowerShell 中手动传递参数不同。任何帮助表示赞赏...
void encrypt_message(const char * message_in, char * encrypted_return)
{
char encryption_cmd[1024] = { '\0' };
strcat(encryption_cmd, "echo '");
strcat(encryption_cmd, message_in);
strcat(encryption_cmd, "' | openssl.exe dgst -sha256 -hmac ");
strcat(encryption_cmd, SEC_KEY);
printf("CMD= %s\n",encryption_cmd);
char psBuffer[1024] = { '\0' };
FILE *pPipe;
if ((pPipe = _popen(encryption_cmd, "rt")) == NULL)
return;
while (fgets(psBuffer, 1024, pPipe));
if (!feof(pPipe))
printf("Error: Failed to read the pipe to the end.\n");
sscanf(psBuffer, "(stdin)= %s", encrypted_return);
printf("RESULT= %s\n",encrypted_return);
}
但是,当我在 PowerShell 中手动调用时,我得到了不同的结果
看起来好像 popen 在其中洒了一些东西,而 openssl 正在解释,产生了不同的结果。但我不能缩小到底是什么!谢谢
【问题讨论】:
-
unicode 激活了吗?
-
不是........
-
看起来
cmd的echo正在输出包括引号。 PowerShell 不包括引号 -
在 cmd/PowerShell 中执行不同的引号/无引号组合我仍然无法在 shell 之间获得相同的结果。
-
所以它似乎不一致,也许关于空格也是如此。不确定您是否可以在这里依赖任何东西。
标签: c++ c powershell openssl