wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了在Windows上创建代码签名证书以签署PowerShell脚本大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

根据 this guide我尝试创建用于签署PowerSHell脚本的证书: CD C:\OpenSSL-Win32\bin REM Create the key for the Certificate Authority. 2048 is the bit encryptiong, you can set it whatever you want openssl genrsa -out C:\T
根据 this guide我尝试创建用于签署PowerSHell脚本的证书:
CD C:\OpenSSL-Win32\bin
REM Create the key for the Certificate Authority.  2048 is the bit encryptiong,you can set it whatever you want
openssl genrsa -out C:\Test\ca.key 2048
openssl req -config C:\OpenSSL-Win32\bin\openssl.cfg -new -x509 -days 1826 -key C:\Test\ca.key -out C:\Test\ca.crt
REM Now I'm creaTing the private key that will be for the actual code signing cert
openssl genrsa -out C:\Test\codesign.key 2048
openssl req -config C:\OpenSSL-Win32\bin\openssl.cfg -new -key C:\Test\codesign.key -reqexts v3_req -out C:\Test\codesign.csr
openssl x509 -req -days 1826 -in C:\Test\codesign.csr -CA C:\Test\ca.crt -CAkey C:\Test\ca.key -extfile C:\OpenSSL-Win32\bin\cnf\opensslTest.cnf -set_serial 01 -out C:\Test\codesign.crt
openssl pkcs12 -export -out C:\Test\codesign.pfx -inkey C:\Test\codesign.key -in C:\Test\codesign.crt

发生以下错误

C:\OpenSSL-Win32\bin>openssl x509 -req -days 1826 -in C:\Test\codesign.csr -CA C:\Test\ca.crt -CAkey C:\Test\ca.key -extfile C:\OpenSSL-Win32\bin\cnf\openssl.cnf -set_serial 01 -out C:\Test\codesign.crt
Error Loading extension section default
14516:error:22097082:X509 V3 routInes:do_ext_nconf:unkNown extension name:crypto\x509v3\v3_conf.c:78:
14516:error:22098080:X509 V3 routInes:X509V3_EXT_nconf:error in extension:crypto\x509v3\v3_conf.c:47:name=HOME,value=.

我使用了@L_450_6@.我找到的每个其他指南都创建了无法用于代码签名的证书.

Windows上的OpenSSL没有必要.在Windows 7上,您可以使用我在TechNet脚本库中发布的自己的PowerSHell脚本: Self-signed certificate generator (PowerShell).用法可以是这样的
New-SelfsignedCertificateEx -Subject "CN=Test Code Signing" `
-EKU "Code Signing" `
-KeySpec "Signature" ` 
-KeyUsage "DigitalSignature" `
-FriendlyName "Test code signing"
-NotAfter $([datetiR_657_11845@e]::Now.AddYears(5))

(第一个例子).

从Windows 8开始,您可以使用内置的certreq.exe工具生成证书.使用证书配置创建INF文件,例如:

[Newrequest]
Subject = "CN=Test Code Signing"
KeyLength = 2048
KeyAlgorithm = RSA
ProviderName = "Microsoft Enhanced RSA and AES Cryptographic Provider"
MachineKeySet = false
Exportable = true
KeySpec = 2
KeyUsage = 0x80
requesttype = cert
[EnhancedKeyUsageExtension]
OID=1.3.6.1.5.5.7.3.3 ; Code signing

然后运行以下命令:

Certreq –new path\inffilename.inf

这将生成证书并将其安装到当前用户的证书库.

从Windows 10开始,您可以使用内置PowerSHell cmdlet,如下所示:

New-SelfSignedCertificate -CertStoreLOCATIOn cert:\currentuser\my `
-Subject "CN=Test Code Signing" `
-KeyAlgorithm RSA `
-KeyLength 2048 `
-Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" `
-KeyExportPolicy Exportable `
-KeyUsage DigitalSignature `
-Type CodeSigningCert

但是,在生产环境中进行代码签名的自签名证书使用是dsicouraged.您应该仅在测试环境中使用它们.

对于私人使用(仅限组织内),您应检查公司是否已拥有PKI基础架构并联系相应人员以获得公司批准的代码签名证书.

对于公共脚本(您将随软件包一起分发或向客户提供脚本),我建议从全球信任的商业CA提供商处购买代码.

大佬总结

以上是大佬教程为你收集整理的在Windows上创建代码签名证书以签署PowerShell脚本全部内容,希望文章能够帮你解决在Windows上创建代码签名证书以签署PowerShell脚本所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。