The Chilkat .NET component provides a free SysUtil class with a ShellExecuteW method that makes it easy to run programs from within a C# or VB.NET program. This example shows how to use the makecert.exe tool, which provided with the Microsoft .NET Platform SDK, to create a self-signed X.509 digital certificate.
/* Flags for ShellExecuteW:
#define SW_HIDE 0
#define SW_SHOWNORMAL 1
#define SW_NORMAL 1
#define SW_SHOWMINIMIZED 2
#define SW_SHOWMAXIMIZED 3
#define SW_MAXIMIZE 3
#define SW_SHOWNOACTIVATE 4
#define SW_SHOW 5
#define SW_MINIMIZE 6
#define SW_SHOWMINNOACTIVE 7
#define SW_SHOWNA 8
#define SW_RESTORE 9
#define SW_SHOWDEFAULT 10
#define SW_FORCEMINIMIZE 11
#define SW_MAX 11
*/
int displayFlags = 0;
string x509Name = "CN=Acme Construction,";
x509Name += "O=Acme,";
x509Name += "L=Chicago,S=Illinois,C=US,E=acme@chilkatsoft.com";
string outputCertificateFile = "acme.cer";
string operation = "open";
string filename = "C:\\Program Files\\Microsoft Visual Studio 8\\SDK\\v2.0\\Bin\\makecert.exe";
string param = "-ss my -n \"" + x509Name + "\" " + outputCertificateFile;
string cwd = System.IO.Directory.GetCurrentDirectory();
// Run the makecert command.
Chilkat.SysUtil sysUtil = new Chilkat.SysUtil();
bool success = sysUtil.ShellExecuteW(operation, filename, param, cwd, displayFlags);
if (success)
{
MessageBox.Show("X.509 certificate created!");
}
else
{
MessageBox.Show("Failed to create certificate.");
}
Note: The certificates created using this method are NOT trusted by the external world because they are not issued by a certificate authority.