使用 OpenSSL 库,可以通过执行以下操作创建 CSR(证书签名请求):
openssl genrsa -out rsa.key 1024
openssl req -new -key rsa.key -out output.csr -config config.txt
Run Code Online (Sandbox Code Playgroud)
其中config.txt包含要在证书中使用的专有名称。
我想在 Windows 下使用 C# 做类似的事情。但是,该方法createPKCS10不需要您提供 RSA 密钥。
有没有办法让 C# 生成一个显式的 RSA 私钥,然后使用该私钥创建 CSR?
您可以使用OpenSSL.NET库来完成此任务。以下例程应该是您所需要的:
public static void Main()
{
Console.Write(GenerateCsr(GenerateRsaKeyPair()));
}
/// <summary>
/// Generates a 2048 bit RSA key pair.
/// </summary>
/// <returns>The key container</returns>
public static CryptoKey GenerateRsaKeyPair()
{
using(var rsa = new RSA())
{
rsa.GenerateKeys(2048, 0x10021, null, null);
return new CryptoKey(rsa);
}
}
/// <summary>
/// Generates a CSR file content using to the hard-coded details and the given key.
/// </summary>
/// /// <param name="key">RSA key to be used</param>
/// <returns>The CSR file content</returns>
public static string GenerateCsr(CryptoKey key)
{
using (var subject = new X509Name
{
SerialNumber = "1234567890",
Organization = "My Company"
// Add more details here...
})
{
using (var req = new X509Request(0, subject, key))
{
return req.PEM;
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我看来,您可以在这里找到问题的答案:http://msdn.microsoft.com/en-us/library/ms867026.aspx。
请参阅使用 C# 读取证书签名请求来了解一个封闭的问题。
| 归档时间: |
|
| 查看次数: |
9978 次 |
| 最近记录: |