如何在C#进程中使用Openssl命令签署CSR
本文关键字:Openssl 命令 签署 CSR 进程 | 更新日期: 2023-09-27 18:29:36
我已经能够通过C#进程使用Openssl命令生成密钥以及从密钥中生成CSR,如下所示:
startInfo.Arguments = @"ecparam -out ..'..'Certificates'client.key -name secp521r1 -genkey ";
try
{
Console.WriteLine("Generating keys...");
System.Diagnostics.Process.Start(startInfo).WaitForExit();
Console.WriteLine("Keys generated");
startInfo.Arguments = @"req -new -nodes -key ..'..'Certificates'client.key -subj '' -outform pem -out ..'..'Certificates'client.req";
Console.WriteLine("Generating CSR ");
System.Diagnostics.Process.Start(startInfo).WaitForExit();
Console.WriteLine("CSR generated");
然而,我不能从上面的代码生成SCR使用这个代码:
startInfo.Arguments = @"ca -batch -keyfile ..'..'ca'ca.key -cert ..'..'ca'cacert.pem -in ..'..'Certificates'client.req -outform PEM -out client.pem";
Console.WriteLine("Signing Cert...");
System.Diagnostics.Process p= System.Diagnostics.Process.Start(startInfo);
//This step is executed without error but does not generate the signed certificate client.pem.
//Strangely enough, this command works fine when executed in the openssl shell and it does generate the signed client.pem
p.WaitForExit();
Console.WriteLine("Signing done");
}
我试着在VS2012中调试Openssl,当命令被执行时,看看哪里出了问题,但我不知道怎么做。正如我所说,签名命令在opensslshell中运行良好,但它在这里不起作用,也不会引发任何错误。
知道吗?
我能够解决它,只需将index.txt和serial.txt移动到bin目录中。
就是这样。