i have followed msdn article to generate pfx file using powershell. so i have executed sequentially
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
So far everything is good but when i try to get the pfx certificate using comman below. it prompts to enter the password I used. i am trying exact same password as "mypassword" but it returns error below
Get-PfxCertificate -FilePath mycert.pfx
Get-PfxCertificate : The specified network password is not correct. At line:1 char:1
I am trying to create a build pipeline on azure devops using this certificate and password but azure pipeliness gives me the same error message.
If i create a pfx file using Visual Studio 2019, Get-PfxCertificate with the password i give, works fine. But Azure pipeliness returns another error.
So my questions are,
what is the difference creating pfx file using Visual Studio 2019 vs PowerShell? why VS 2019 generated pfx doesnt work.
why Get-PfxCertificate doesnt accept the password i use to generate?
Regarding 2nd issue I thought that it might be something to do with plaintext vs SecureString. thats why I tried below command as well as stated in the docs. It tells me that -password is not recognized.
$pwd = ConvertTo-SecureString -String mypassword -Force -AsPlainText
Get-PfxCertificate -FilePath mycert.pfx -Password $pwd -NoPromptForPassword
Error:
Get-PfxCertificate : A parameter cannot be found that matches parameter name 'Password'.
At line:2 char:60