如何从 C# 生成服务器 SSL 证书签名请求 (CSR)?如果 PowerShell 是一个更好的选择,那也是一个很好的解决方案。
问问题
1814 次
2 回答
2
一些通用指针:
- http://msdn.microsoft.com/en-us/library/aa382488%28VS.85%29.aspx
- http://msdn.microsoft.com/en-us/library/aa382820%28VS.85%29.aspx
- http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.aspx
- http://blogs.msdn.com/b/alejacma/archive/2008/09/05/how-to-create-a-certificate-request-with-certenroll-and-net-c.aspx
- http://learn.iis.net/page.aspx/144/how-to-set-up-ssl-on-iis-7/
编辑 - 根据评论:
MS提供的COM对象CertEnroll
可以通过PowerShell访问...
于 2011-09-29T14:35:17.410 回答
2
我知道是三年后,但 Yahia 解决方案中的链接表明它们不适用于 Server 2008。使用 PowerShell,我能够使用 Server 2008 附带的 Certreq.exe 来生成 CSR。Certreq 的文档以及 INF 文件的完整格式在此处。当然,用您自己的值替换可分辨名称。这些字母对应于这些字段:
- CN : 通用名称
- O : 组织
- OU : 组织单位
- L : 城市/地区
- S : 州/省
- C : 国家/地区
该脚本假定您有一个名为 TEMP 的环境变量,它指向您具有写入权限的目录:
$reqFile = 'C:\ChangeMe\Request.req'
Push-Location $env:TEMP
@"
[NewRequest]
Subject = "CN=www.contoso.com, O=Contoso Inc, OU=Sales, L=Redmond, S=Washington, C=US"
ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
KeyLength = 2048
MachineKeySet = true
FriendlyName = "www.contoso.com"
[RequestAttributes]
CertificateTemplate="WebServer"
"@ | Out-File .\request.inf -Encoding default -Force
certreq -f -new request.inf `"$reqFile`"
Pop-Location
For those who are new to PowerShell, the @"
and "@
delimiters must not be indented. (These define what is known as a "Here-String"... more information here.)
于 2014-11-26T17:46:55.060 回答