![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Load PKCS12 / PFX and Access ContentsLoads a PKCS12 / PFX file and iterates over the contents which include private keys and certificates. Note: This example requires Chilkat v11.0.0 or greater.
#include <C_CkPfxW.h> #include <C_CkPrivateKeyW.h> #include <C_CkCertW.h> void ChilkatSample(void) { BOOL success; HCkPfxW pfx; int numPrivateKeys; HCkPrivateKeyW privKey; int i; HCkCertW cert; int numCerts; success = FALSE; pfx = CkPfxW_Create(); // Load the PKCS12 from a file success = CkPfxW_LoadPfxFile(pfx,L"/someDir/my.p12",L"pfxFilePassword"); if (success == FALSE) { wprintf(L"%s\n",CkPfxW_lastErrorText(pfx)); CkPfxW_Dispose(pfx); return; } numPrivateKeys = CkPfxW_getNumPrivateKeys(pfx); privKey = CkPrivateKeyW_Create(); wprintf(L"Private Keys:\n"); i = 0; while (i < numPrivateKeys) { CkPfxW_PrivateKeyAt(pfx,i,privKey); // Do something with the private key ... i = i + 1; } cert = CkCertW_Create(); numCerts = CkPfxW_getNumCerts(pfx); wprintf(L"Certs:\n"); i = 0; while (i < numCerts) { CkPfxW_CertAt(pfx,i,cert); wprintf(L"%s\n",CkCertW_subjectDN(cert)); // If the certificate has a private key (one of the private keys within the PFX) // then it can also be obtained via the certificate object: if (CkCertW_HasPrivateKey(cert) == TRUE) { wprintf(L"Has private key!\n"); success = CkCertW_GetPrivateKey(cert,privKey); // ... } i = i + 1; } CkPfxW_Dispose(pfx); CkPrivateKeyW_Dispose(privKey); CkCertW_Dispose(cert); } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.