我有一个自签名的代码签名证书,根据这个答案的说明制作,与 一起使用时效果很好signtool.exe
,但是如果我尝试使用 签名Set-AuthenticodeSignature
,它会失败。
为什么我可以使用 签名signtool
,但不能使用Set-AuthenticodeSignature
?
signtool
:Signtool sign /v /n "VetWeb" SetupRDPPermissions.ps1 The following certificate was selected: Issued to: VetWeb Issued by: VetWeb CA Expires: Sat Dec 31 18:59:59 2039 SHA1 hash: 84136EBF8D2603C2CD6668C955F920C6C6482EE4 Done Adding Additional Store Successfully signed: SetupRDPPermissions.ps1 Number of files successfully Signed: 1 Number of warnings: 0
Set-AuthenticodeSignature
:$cert = @(Get-Childitem cert:\CurrentUser\My | Where-Object -FilterScript {$_.Subject -eq 'CN=VetWeb'})[0] Set-AuthenticodeSignature SetupRDPPermissions.ps1 $cert Set-AuthenticodeSignature : Cannot sign code. The specified certificate is not suitable for code signing. At line:1 char:26 + Set-AuthenticodeSignature <<<< SetupRDPPermissions.ps1 $cert + CategoryInfo : InvalidArgument: (:) [Set-AuthenticodeSignature], PSArgumentException + FullyQualifiedErrorId : Argument,Microsoft.PowerShell.Commands.SetAuthenticodeSignatureCommand
Get-Childitem cert:\CurrentUser\My -CodeSigningCert
不返回任何结果
-
$cert | Format-List * PSPath : Microsoft.PowerShell.Security\Certificate::CurrentUser\My\84136EBF8D2603C2CD6668C955F920C6C6482EE4 PSParentPath : Microsoft.PowerShell.Security\Certificate::CurrentUser\My PSChildName : 84136EBF8D2603C2CD6668C955F920C6C6482EE4 PSDrive : cert PSProvider : Microsoft.PowerShell.Security\Certificate PSIsContainer : False Archived : False Extensions : {System.Security.Cryptography.Oid} FriendlyName : IssuerName : System.Security.Cryptography.X509Certificates.X500DistinguishedName NotAfter : 12/31/2039 5:59:59 PM NotBefore : 6/1/2012 1:49:31 PM HasPrivateKey : True PrivateKey : System.Security.Cryptography.RSACryptoServiceProvider PublicKey : System.Security.Cryptography.X509Certificates.PublicKey RawData : {48, 130, 1, 235...} SerialNumber : CF330347F35AC0B4427AFFA82DB51238 SubjectName : System.Security.Cryptography.X509Certificates.X500DistinguishedName SignatureAlgorithm : System.Security.Cryptography.Oid Thumbprint : 84136EBF8D2603C2CD6668C955F920C6C6482EE4 Version : 3 Handle : 479608336 Issuer : CN=VetWeb CA Subject : CN=VetWeb