![]() |
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
(PureBasic) 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.
IncludeFile "CkCert.pb" IncludeFile "CkPrivateKey.pb" IncludeFile "CkPfx.pb" Procedure ChilkatExample() success.i = 0 pfx.i = CkPfx::ckCreate() If pfx.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Load the PKCS12 from a file success = CkPfx::ckLoadPfxFile(pfx,"/someDir/my.p12","pfxFilePassword") If success = 0 Debug CkPfx::ckLastErrorText(pfx) CkPfx::ckDispose(pfx) ProcedureReturn EndIf numPrivateKeys.i = CkPfx::ckNumPrivateKeys(pfx) privKey.i = CkPrivateKey::ckCreate() If privKey.i = 0 Debug "Failed to create object." ProcedureReturn EndIf Debug "Private Keys:" i.i = 0 While i < numPrivateKeys CkPfx::ckPrivateKeyAt(pfx,i,privKey) ; Do something with the private key ... i = i + 1 Wend cert.i = CkCert::ckCreate() If cert.i = 0 Debug "Failed to create object." ProcedureReturn EndIf numCerts.i = CkPfx::ckNumCerts(pfx) Debug "Certs:" i = 0 While i < numCerts CkPfx::ckCertAt(pfx,i,cert) Debug CkCert::ckSubjectDN(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 CkCert::ckHasPrivateKey(cert) = 1 Debug "Has private key!" success = CkCert::ckGetPrivateKey(cert,privKey) ; ... EndIf i = i + 1 Wend CkPfx::ckDispose(pfx) CkPrivateKey::ckDispose(privKey) CkCert::ckDispose(cert) ProcedureReturn EndProcedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.