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


 

 

 

 

 

 

 

 

Create PFX from PEM (Certificate and Private Key Files)

Create a PFX file from a pair of PEM files (the certificate PEM and private key PEM).

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_CkCert.h>
#include <C_CkPrivateKey.h>
#include <C_CkKeyContainer.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkCert cert;
    HCkPrivateKey privkey;
    BOOL bMachineKeyset;
    BOOL bForSigning;
    HCkKeyContainer keyCont;
    BOOL bIncludeCertsInChain;



    cert = CkCert_Create();

    success = CkCert_LoadFromFile(cert,"chilkat_cert.pem");
    if (success != TRUE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        return;
    }

    privkey = CkPrivateKey_Create();
    success = CkPrivateKey_LoadPemFile(privkey,"chilkat_pkey.pem");
    if (success != TRUE) {
        printf("%s\n",CkPrivateKey_lastErrorText(privkey));
        return;
    }

    //  Link the cert to the private key.
    //  Use the current logged-on user's protected key store:

    bMachineKeyset = FALSE;
    //  If the private key is to be used for creating signatures,
    //  set bForSigning = TRUE.  If the private key is to be
    //  used for decrypting, set bForSigning = FALSE

    bForSigning = TRUE;

    //  Select an arbitrary key container name that is unique
    //  to your application.  Make sure it exists:
    keyCont = CkKeyContainer_Create();
    //  The CreateContainer method will create the key container
    //  if it does not already exist, otherwise it will open it.
    //  (The key container is in the Windows protected store.)
    success = CkKeyContainer_CreateContainer(keyCont,"myApp",bMachineKeyset);
    if (success != TRUE) {
        printf("%s\n",CkKeyContainer_lastErrorText(keyCont));
        return;
    }

    success = CkCert_LinkPrivateKey(cert,"myApp",bMachineKeyset,bForSigning);
    if (success != TRUE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        return;
    }

    //  Now export to a PFX:

    bIncludeCertsInChain = FALSE;
    success = CkCert_ExportToPfxFile(cert,"chilkat2.pfx","myPassword",bIncludeCertsInChain);
    if (success != TRUE) {
        printf("%s\n",CkCert_lastErrorText(cert));
        return;
    }

    printf("PFX created!\n");



    CkCert_Dispose(cert);
    CkPrivateKey_Dispose(privkey);
    CkKeyContainer_Dispose(keyCont);

    }

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

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