在Windows上创建代码签名证书以签署PowerShell脚本
发布时间:2020-12-13 23:47:37 所属栏目:Windows 来源:网络整理
导读:根据 this guide我尝试创建用于签署PowerShell脚本的证书: CD C:OpenSSL-Win32binREM Create the key for the Certificate Authority. 2048 is the bit encryptiong,you can set it whatever you wantopenssl genrsa -out C:Testca.key 2048openssl req
根据
this guide我尝试创建用于签署PowerShell脚本的证书:
CD C:OpenSSL-Win32bin REM Create the key for the Certificate Authority. 2048 is the bit encryptiong,you can set it whatever you want openssl genrsa -out C:Testca.key 2048 openssl req -config C:OpenSSL-Win32binopenssl.cfg -new -x509 -days 1826 -key C:Testca.key -out C:Testca.crt REM Now I'm creating the private key that will be for the actual code signing cert openssl genrsa -out C:Testcodesign.key 2048 openssl req -config C:OpenSSL-Win32binopenssl.cfg -new -key C:Testcodesign.key -reqexts v3_req -out C:Testcodesign.csr openssl x509 -req -days 1826 -in C:Testcodesign.csr -CA C:Testca.crt -CAkey C:Testca.key -extfile C:OpenSSL-Win32bincnfopensslTest.cnf -set_serial 01 -out C:Testcodesign.crt openssl pkcs12 -export -out C:Testcodesign.pfx -inkey C:Testcodesign.key -in C:Testcodesign.crt 发生以下错误: C:OpenSSL-Win32bin>openssl x509 -req -days 1826 -in C:Testcodesign.csr -CA C:Testca.crt -CAkey C:Testca.key -extfile C:OpenSSL-Win32bincnfopenssl.cnf -set_serial 01 -out C:Testcodesign.crt Error Loading extension section default 14516:error:22097082:X509 V3 routines:do_ext_nconf:unknown extension name:cryptox509v3v3_conf.c:78: 14516:error:22098080:X509 V3 routines:X509V3_EXT_nconf:error in extension:cryptox509v3v3_conf.c:47:name=HOME,value=. 我使用了OpenSSL v1.1.0c.我找到的每个其他指南都创建了无法用于代码签名的证书.
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 $([datetime]::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 pathinffilename.inf 这将生成证书并将其安装到当前用户的证书库. 从Windows 10开始,您可以使用内置PowerShell cmdlet,如下所示: New-SelfSignedCertificate -CertStoreLocation cert:currentusermy ` -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提供商处购买代码. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- .Net Windows Services和InstallState文件 – 真的需要吗?
- Windows 设置定时任务
- 如何确定接口是否是Windows PC上的物理LAN端口?
- Windows 10 IoT Raspberry Pi 2:自动启动发布的应用程序
- Windows Azure表存储帐户的限制
- 所有版本的Windows 7都包含.NET Framework 3.5版吗?
- 我在哪里可以获得64位Windows转储中的当前滴答计数?
- windows-server-2008 – Sharepoint的免费版本是什么?我从
- windows – 使批处理文件FOR命令工作没有通配符?
- windows-server-2008-r2 – 我在哪里授予权限,以便用户可以
推荐文章
站长推荐
- 如何使用.net获取Windows服务的phyiscal路径?
- windows-phone-7 – Windows Phone 8平台上的GPS
- 从uint []转换为int []的C#调用ToList()异常
- .net – 在Windows应用商店应用中保存文件
- 如何在Windows XP中添加启动 – >运行快捷方式?
- windows – 控制台FTPS(不是SFTP)客户端?
- 在没有Microsoft扩展的情况下构建Visual C
- Windows – IIS自签名证书故障 – “参数不正确”
- ssize_t 重定义 不同的基类型
- windows-server-2008 – 在Windows 2008环境中禁
热点阅读