2

如何从 C# 生成服务器 SSL 证书签名请求 (CSR)?如果 PowerShell 是一个更好的选择,那也是一个很好的解决方案。

4

2 回答 2

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 回答