Here is a variation of posted by Guilherme Nascimento :
public void ExecutarComandoSSL(string arquivoCNF, string arquivoCSR) {
using (System.Diagnostics.Process processo = new System.Diagnostics.Process()) {
processo.StartInfo.FileName = Environment.GetEnvironmentVariable("comspec");
processo.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
processo.StartInfo.Arguments = string.Format("/c openssl req -new -config {0} -out \"{1}\"", arquivoCNF, arquivoCSR);
//processo.StartInfo.CreateNoWindow = true;
processo.Start();
processo.WaitForExit();
}
}
Note : The command will execute in the current user's desktop directory. Information .
Do the following, in the form, put:
- Two buttons, one to fetch the CNF , and another to save in CSR format.
- Place a
OpenFileDialog
component.
Create a class to retrieve and save information about the files:
public static class VariaveisGlobais
{
public static string CNF { get; set; }
public static string CSR { get; set; }
}
In the button responsible for searching the CNF file, place:
DialogResult resposta = openFileDialog1.ShowDialog();
if (resposta == DialogResult.OK) {
string arquivo = openFileDialog1.FileName;
VariaveisGlobais.CNF = arquivo;
VariaveisGlobais.CSR = "cert.csr"; // Leia a sugestão
}
Hint : You can use the SaveFileDialog
component to allow the user to save the file to location of your choice.
In the CSR button, save the file:
string arquivoCNF = VariaveisGlobais.CNF;
string arquivoCSR = VariaveisGlobais.CSR;
// Aqui você poderia tratar o conteúdo das variáveis
ExecutarComandoSSL(arquivoCNF, arquivoCSR);