Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

February 6, 2008

Creating a Self-Signed X.509 Certificate in C#

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_MAXIMIZE         3
#define SW_SHOW             5
#define SW_MINIMIZE         6
#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,";
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!");
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.

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.