我有以下 Powershell 脚本来为 C# 应用程序创建新证书:
$expirationDate = [datetime]::Today.AddYears(5)
$thumb = (New-SelfSignedCertificate -CertStoreLocation cert:\localmachine\my -DnsName $env:USERDNSDOMAIN -KeyExportPolicy Exportable -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -NotAfter $expirationDate).Thumbprint
$pwd = '123456'
$SSpwd = ConvertTo-SecureString -String $pwd -Force -AsPlainText
$destinationDirectory = "C:\Test\"
$filename = "mycert.pfx"
$pathAndFilename = $destinationDirectory + $filename
Export-PfxCertificate -cert "cert:\localmachine\my\$thumb" -FilePath $pathAndFilename -Password $SSpwd
Run Code Online (Sandbox Code Playgroud)
它运行良好。然后在 Visual Studio 的应用程序中,在项目属性页面的“签名”选项卡上,单击“从文件中选择”并浏览到该文件,我得到:
所选证书对于编码签名无效。选择另一个证书文件。
我究竟做错了什么?
根据@ConnorLSW 评论添加信息。我现在有这个脚本:
$pwd = '123456'
$SSpwd = ConvertTo-SecureString -String $pwd -Force -AsPlainText
$destinationDirectory = "C:\Test\"
$filename = "mycert.pfx"
$pathAndFilename …Run Code Online (Sandbox Code Playgroud)