Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
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).
#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.