Case
安装openSSL,添加到环境变量
第一种方式,进入到openssl环境,然后执行命令
openssl
genrsa -des3 -passout pass:"123456" -out D:\test1.key
第二种方式,通过PowerShell调用openssl.exe执行命令
openssl genrsa -des3 -passout pass:"123456" -out D:\test2.key
Check
Check的时候会提示输入密码,我们均输入:123456
Check test1.key:
openssl rsa -check -in D:\test1.key
输出错误:unable to load Private Key
Check test2.key:
openssl rsa -check -in D:\test2.key
正常
Why
本质原因就是命令参数写法有问题导致,-passout pass:"123456"应该写成-passout "pass:123456"就不会有差异了。
第一种方式,进入openSSL环境,密码就是pass:后的所有字符,包括特殊字符,所以密码为:"123456"(包括引号)
第二种方式,PowerShell调用openSSL.exe,PowerShell会删除-passout pass:"123456"中的引号,密码为:123456
cmd和PowerShell调用其他exe时候参数中引号传递问题?
示例程序

cmd调用,可以看到,只是删除了双引号

PowerShell调用,单双引号都被删除

如果确实需要传递双引号,那就转义'\"',或者使用"""
ref
https://www.openssl.org/docs/manmaster/man1/openssl-passphrase-options.html
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.2
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-7.2#passing-arguments-that-contain-quote-characters
