【发布时间】:2020-03-09 01:04:35
【问题描述】:
我已关注 msdn article 使用 powershell 生成 pfx 文件。所以我已经按顺序执行了
New-SelfSignedCertificate -Type Custom -Subject "CN=Contoso Software, O=Contoso Corporation, C=US" -KeyUsage DigitalSignature -FriendlyName "Your friendly name goes here" -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}")
$pwd = ConvertTo-SecureString -String mypassword -Force -AsPlainText
Export-PfxCertificate -cert "Cert:\CurrentUser\My\<Certificate Thumbprint>" -FilePath mycert.pfx -Password $pwd
到目前为止,一切都很好,但是当我尝试使用下面的命令获取 pfx 证书时。它提示输入我使用的密码。我正在尝试与“mypassword”完全相同的密码,但它在下面返回错误
Get-PfxCertificate -FilePath mycert.pfx
Get-PfxCertificate : 指定的网络密码不正确。在 行:1 字符:1
我正在尝试使用此证书和密码在 azure devops 上创建构建管道,但 azure pipeliness 给了我相同的错误消息。
如果我使用 Visual Studio 2019 创建 pfx 文件,使用我提供的密码获取 PfxCertificate 可以正常工作。但 Azure 管道返回另一个错误。
所以我的问题是,
使用 Visual Studio 2019 与 PowerShell 创建 pfx 文件有什么区别?为什么 VS 2019 生成的 pfx 不起作用。
为什么 Get-PfxCertificate 不接受我用来生成的密码?
关于第二个问题,我认为这可能与纯文本与 SecureString 有关。这就是为什么我尝试以下命令以及docs 中所述的原因。它告诉我 -password 无法识别。
$pwd = ConvertTo-SecureString -String mypassword -Force -AsPlainText
Get-PfxCertificate -FilePath mycert.pfx -Password $pwd -NoPromptForPassword
错误:
Get-PfxCertificate : A parameter cannot be found that matches parameter name 'Password'.
At line:2 char:60
【问题讨论】: