C# Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C# Examples

Bounced Mail
Bz2
Character Encoding
CSV
DKIM / DomainKey
Digital Certificates
Digital Signatures
Email
Email Object
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH
SSH Tunnel
SSH Key
SFTP
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

Export Certificate and Private Key to PFX

Download Chilkat .NET for 4.0 Framework

Download Chilkat .NET for 64-bit 4.0 Framework (x64)

Download Chilkat .NET for 2.0 / 3.5 Framework

Download Chilkat .NET for 64-bit 2.0 / 3.5 Framework (x64)

Download Chilkat .NET for 1.0 / 1.1 Framework

Demonstrates how to export a digital certificate, it's private key, and potentially all certificates in the chain of authentication to a PFX file.

bool success;

//  This object is used to create a certificate store object.
Chilkat.CreateCS ccs = new Chilkat.CreateCS();

Chilkat.CertStore certStore;
//  Open the local machine certificate store read-only.
ccs.ReadOnly = true;
certStore = ccs.OpenLocalSystemStore();

//  Can we find a certificate by email address?
Chilkat.Cert cert;
cert = certStore.FindCertBySubjectE("admin@chilkatsoft.com");
if (cert == null ) {
    //  Open the current-user certificate store and check it instead.

    textBox1.Text += "Checking current-user certificate store..." + "\r\n";
    textBox1.Refresh();

    certStore = ccs.OpenCurrentUserStore();

    cert = certStore.FindCertBySubjectE("admin@chilkatsoft.com");
    if (cert == null ) {
        textBox1.Text += "Failed to find certificate!" + "\r\n";
        textBox1.Refresh();
        return;
    }

}

//  Does this certificate have a private key accessible
//  to the calling process?  Private keys are *not* stored
//  within the certificate store.  Private keys are stored
//  in a key container in a Windows protected store.  It
//  can be one of two protected stores: the protected store for
//  the current logged-in user account, or the "machine-key"
//  protected store.  The private key must both exist in a
//  protected store, and the process must have permission to
//  access it...

//  You can only export to a PFX if the private key exists
//  and is accessible.

if (cert.HasPrivateKey() == true) {

    //  Export to a PFX.
    //  Provide a password that will be required whenever the PFX is opened.
    //  Also, include all certs in the chain of authentication.
    bool bIncludeChain;
    bIncludeChain = true;
    success = cert.ExportToPfxFile("myCert.pfx","myPassword",bIncludeChain);
    if (success != true) {
        textBox1.Text += cert.LastErrorText + "\r\n";
        textBox1.Refresh();
    }
    else {
        textBox1.Text += "Exported to PFX!" + "\r\n";
        textBox1.Refresh();
    }

}
else {
    textBox1.Text += "Certificate does not have a private key available" + "\r\n";
    textBox1.Refresh();
}

//  The Chilkat Certificate, Certificate Store, Private Key,
//  Public Key, and Key Container classes / objects are freeware.

//  They are used by and included with the Chilkat Email,
//  Crypt, S/MIME, and other commercial Chilkat components.

 

© 2000-2012 Chilkat Software, Inc. All Rights Reserved.

Email Component · XML Parser