Powershell正在使用错误的密码创建代码签名证书,我做错了什么



我正在尝试创建一个自签名的代码签名证书,但当我尝试使用它对.exe进行签名时,我会收到此SignTool错误SignTool Error: The specified PFX password is not correct.

以下是我运行的创建证书的命令,使用密码将其导出到pfx,然后签署.exe

$password = "password"
$certificate = New-SelfSignedCertificate -DnsName "MyCompany, Dev" -Type CodeSigning -CertStoreLocation Cert:CurrentUserMy
$certificatePassword = ConvertTo-SecureString -String $password -Force –AsPlainText
Export-PfxCertificate -Cert "cert:CurrentUserMy$($certificate.Thumbprint)" -FilePath "C:UsersmeProjectCSCDev.pfx" -Password $certificatePassword
SignTool sign /f "C:UsersmeProjectCSCDev.pfx" "C:UsersmeProjectMyCompanyApp.exe" /p $certificatePassword

做错了什么?

如上所述,我会使用Powershell cmdlet,而不是导出代码签名证书:

$cert=(dir cert:currentusermy -CodeSigningCert)
$script = Read-Host -Prompt "Please enter (without quotes) the path to the file you are signing `r`n
Example: \servermy folderprojects.ps1 `r`n"
# Alternative timestamp sources:
#http://timestamp.comodoca.com/authenticode
#http://timestamp.globalsign.com/scripts/timestamp.dll
#http://tsa.starfieldtech.com
#
Try {
Set-AuthenticodeSignature -FilePath $($script) -Certificate $cert -TimestampServer http://timestamp.digicert.com -Verbose -ErrorAction Stop
}
Catch { 
$_
}