Programming Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

C Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
MIME
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip


 

 

 

 

 

 

 

 

PFX to PEM (Certificate and Private Key Files)

Export a certificate and private key from a PFX to a pair of PEM files.

Download Chilkat C/C++ Libraries for VC++ 9.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32

Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64

Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE

Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible

#include <C_CkCertStore.h>
#include <C_CkCert.h>
#include <C_CkPrivateKey.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkCertStore certStore;
    const char * password;
    HCkCert cert;
    HCkPrivateKey pvkey;


    certStore = CkCertStore_Create();

    //  Load the PFX file into a certificate store object

    password = "myPassword";
    success = CkCertStore_LoadPfxFile(certStore,"chilkat.pfx",password);
    if (success != TRUE) {
        printf("%s\n",CkCertStore_lastErrorText(certStore));
        return;
    }

    //  Find the cert to be exported by the subject:

    cert = CkCertStore_FindCertBySubject(certStore,"Chilkat Software, Inc.");
    if (cert == 0 ) {
        printf("Certificate not found.\n");
        return;
    }

    //  Does this cert have a private key?
    if (CkCert_HasPrivateKey(cert) == TRUE) {

        //  Get the private key.

        pvkey = CkCert_ExportPrivateKey(cert);

        //   Export the private key to a PEM file:
        success = CkPrivateKey_SaveRsaPemFile(pvkey,"chilkat_pkey.pem");
        if (success != TRUE) {
            printf("%s\n",CkPrivateKey_lastErrorText(pvkey));
            return;
        }

        CkPrivateKey_Dispose(pvkey);

    }

    //  Save the cert to a PEM file:
    success = CkCert_ExportCertPemFile(cert,"chilkat_cert.pem");
    if (success != TRUE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        return;
    }

    CkCert_Dispose(cert);



    CkCertStore_Dispose(certStore);

    }

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

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