PHP escapeshellarg搞砸了我的密码

问题描述 投票:0回答:1
$passphrase = "';__!!??()[]";

$passphrase = escapeshellarg($passphrase);
shell_exec("openssl\openssl.exe genrsa -des3 -passout pass:${passphrase} -out test.key 2048");

#Here the password works
echo system("openssl\openssl.exe rsa -in test.key -passin pass:${passphrase} -noout -text");

此代码适用于使用openssl生成密钥。我也可以毫无问题地阅读密钥。但是当我想从命令行读取密钥时,我无法解密它。我使用与代码中完全相同的命令。唯一的区别是,我将密码复制到命令行,因为它是在代码中写入的。这总是因为解密错误而失败。

我该如何解决这个问题?

编辑:使这更清楚。从终端运行时,这不起作用:

openssl\openssl.exe rsa -in test.key -passin pass:"';__!!??()[]" -noout -text
php encoding
1个回答
0
投票

为什么不使用PHP的OpenSSL库而不是shell?

http://php.net/manual/en/ref.openssl.php

© www.soinside.com 2019 - 2024. All rights reserved.