C# Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

C# Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML to XML
HTTP
IMAP
Encryption
MHT / HTML Email
MIME
RSA Encryption
S/MIME
Socket
Spider
Tar Archive
Upload
XML
XMP
Zip Compression


More Examples...
Email Object
POP3
SMTP
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
SSH Key
SSH
SSH Tunnel
SFTP

Unreleased...
Bzip2
LZW
Bz2
Icon

 

 

 

 

 

 

Export certificates and public/private keys from a PFX

Demonstrates how to export certificates and public/private keys from a PFX file.

Download Chilkat .NET for 2.0 Framework

Download Chilkat .NET for 1.0 / 1.1 Framework

bool success;
Chilkat.CertStore certStore = new Chilkat.CertStore();

//  Load the PFX file into a certificate store object
string password;
password = "myPassword";
success = certStore.LoadPfxFile("chilkat.pfx",password);
if (success != true) {
    MessageBox.Show(certStore.LastErrorText);
    return;
}

int i;
int numCerts;
numCerts = certStore.NumCertificates;

Chilkat.Cert cert;
string fname;
for (i = 0; i <= numCerts - 1; i++) {

    cert = certStore.GetCertificate(i);

    textBox1.Text += cert.SubjectDN + "\r\n";
    textBox1.Refresh();
    textBox1.Text += "---" + "\r\n";
    textBox1.Refresh();

    //  Save the cert in DER format:
    fname = "cert" + Convert.ToString(i) + ".der";
    cert.ExportCertDerFile(fname);

    //  Save the cert in PEM format:
    fname = "cert" + Convert.ToString(i) + ".pem";
    cert.ExportCertPemFile(fname);

    //  Does this cert have a private key?
    if (cert.HasPrivateKey() == true) {

        //  Get the private key.
        Chilkat.PrivateKey pvkey;
        pvkey = cert.ExportPrivateKey();

        //  Save the private key to a PKCS8 DER-encoded file
        fname = "pvkey" + Convert.ToString(i) + "_pkcs8.der";
        pvkey.SavePkcs8File(fname);

        //  Save the private key to a PKCS8 PEM-encoded file
        fname = "pvkey" + Convert.ToString(i) + "_pkcs8.pem";
        pvkey.SavePkcs8PemFile(fname);

        //  Save the private key to a RSA DER-encoded file
        fname = "pvkey" + Convert.ToString(i) + "_rsa.der";
        pvkey.SaveRsaDerFile(fname);

        //  Save the private key to a RSA PEM-encoded file
        fname = "pvkey" + Convert.ToString(i) + "_rsa.pem";
        pvkey.SaveRsaPemFile(fname);

        //  Save the private key to an XML file
        //  This format is Chilkat-specific, but easily parsed,
        //  making it easy to get the modulus, exponent,
        //  P, Q, DP, DQ, InverseQ, and D.
        fname = "pvkey" + Convert.ToString(i) + ".xml";
        pvkey.SaveXmlFile(fname);

    }

    //  Now get the public key and save it to various file formats:
    Chilkat.PublicKey pubkey;
    pubkey = cert.ExportPublicKey();

    //  Save to an OpenSSL DER format file:
    fname = "pubkey" + Convert.ToString(i) + "_openSsl.der";
    pubkey.SaveOpenSslDerFile(fname);

    //  Save to an OpenSSL PEM format file:
    fname = "pubkey" + Convert.ToString(i) + "_openSsl.pem";
    pubkey.SaveOpenSslPemFile(fname);

    //  Save to an RSA DER format file:
    fname = "pubkey" + Convert.ToString(i) + "_rsa.der";
    pubkey.SaveRsaDerFile(fname);

    //  Save to an XML file:
    //  This format is Chilkat-specific, but easily parsed,
    //  making it easy to get the modulus and exponent.
    fname = "pubkey" + Convert.ToString(i) + ".xml";
    pubkey.SaveXmlFile(fname);

}

//  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.

 

Need a specific example? Send a request to support@chilkatsoft.com

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

Email Component · XML Parser