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

ztigrdn8  于 2022-11-10  发布在  Shell
关注(0)|答案(1)|浏览(98)

我正在尝试创建自签名的代码签名证书,但当我尝试使用它对.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:\CurrentUser\My
$certificatePassword = ConvertTo-SecureString -String $password -Force –AsPlainText
Export-PfxCertificate -Cert "cert:\CurrentUser\My\$($certificate.Thumbprint)" -FilePath "C:\Users\me\Project\CSCDev.pfx" -Password $certificatePassword
SignTool sign /f "C:\Users\me\Project\CSCDev.pfx" "C:\Users\me\Project\MyCompanyApp.exe" /p $certificatePassword

到底做错了什么?

8ehkhllq

8ehkhllq1#

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

$cert=(dir cert:currentuser\my\ -CodeSigningCert)

$script = Read-Host -Prompt "Please enter (without quotes) the path to the file you are signing `r`n
Example: \\server\my folder\projects.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 { 
    $_
}

相关问题