Uwp Powershell生成的pfx文件密码问题

Uwp Powershell生成的pfx文件密码问题,uwp,pfx,Uwp,Pfx,我跟随msdn使用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"

我跟随msdn使用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
Get-PfxCertificate:指定的网络密码不正确。在 行:1字符:1

我正试图使用此证书和密码在azure devops上创建一个构建管道,但azure Pipelisty给了我相同的错误消息

如果我使用VisualStudio2019创建一个pfx文件,使用我提供的密码获取PfxCertificate,效果很好。但是Azure Pipebility返回另一个错误

所以我的问题是

使用Visual Studio 2019和PowerShell创建pfx文件有什么区别?为什么VS2019生成的pfx不起作用

为什么Get-PfxCertificate不接受我用来生成的密码

关于第二个问题,我认为这可能与纯文本和SecureString有关。这就是为什么我试着服从命令,也试着服从命令。它告诉我-密码无法识别

   $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

我不知道1,但是对于2,您不应该使用大写字母p作为-Password命令吗?请参见参考,其中说明了以下内容:

Get-PfxCertificate
   -LiteralPath <String[]>
   [-Password <SecureString>]
   [-NoPromptForPassword]
   [<CommonParameters>]
如果问题仍然存在,显然还有其他问题,但我会先尝试一下,看看它是否因为这个原因无法识别命令

据我所知,应该没有太大的区别,但老实说,我不太确定它到底是如何在VS中完成的

Get-PFXCertificate cmdlet的-Password参数仅添加到PS版本6.1+中,可能需要检查您在Azure中使用的版本,因为我在本地遇到了相同的问题,这是因为我在5.1上


我只是想给其他任何人一个答案,我有这个愚蠢的问题。如果您在powershell中使用$之类的符号而不使用撇号或双引号,则生成仍然有效,并且您得到的是pfx文件,但密码与您设置的密码不同:这就是azure devops返回此错误的原因

不,是相同的错误。我认为它不区分大小写,是同一个错误还是同样的错误?Powershell有时会给出“错误-不起作用”,但不会详细说明出错的原因,在本例中,可能是其他原因。考虑在代码中添加TIG/catch?完全一样的错误。你可以很容易地测试它。我可能需要2分钟来测试:
Get-PfxCertificate
   -LiteralPath <String[]>
   [-Password <SecureString>]
   [-NoPromptForPassword]
   [<CommonParameters>]