![]() |
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
(DataFlex) 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.
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Handle hoPfx Integer iNumPrivateKeys Variant vPrivKey Handle hoPrivKey Integer i Variant vCert Handle hoCert Integer iNumCerts String sTemp1 Boolean bTemp1 Move False To iSuccess Get Create (RefClass(cComChilkatPfx)) To hoPfx If (Not(IsComObjectCreated(hoPfx))) Begin Send CreateComObject of hoPfx End // Load the PKCS12 from a file Get ComLoadPfxFile Of hoPfx "/someDir/my.p12" "pfxFilePassword" To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoPfx To sTemp1 Showln sTemp1 Procedure_Return End Get ComNumPrivateKeys Of hoPfx To iNumPrivateKeys Get Create (RefClass(cComChilkatPrivateKey)) To hoPrivKey If (Not(IsComObjectCreated(hoPrivKey))) Begin Send CreateComObject of hoPrivKey End Showln "Private Keys:" Move 0 To i While (i < iNumPrivateKeys) Get pvComObject of hoPrivKey to vPrivKey Get ComPrivateKeyAt Of hoPfx i vPrivKey To iSuccess // Do something with the private key ... Move (i + 1) To i Loop Get Create (RefClass(cComChilkatCert)) To hoCert If (Not(IsComObjectCreated(hoCert))) Begin Send CreateComObject of hoCert End Get ComNumCerts Of hoPfx To iNumCerts Showln "Certs:" Move 0 To i While (i < iNumCerts) Get pvComObject of hoCert to vCert Get ComCertAt Of hoPfx i vCert To iSuccess Get ComSubjectDN Of hoCert To sTemp1 Showln sTemp1 // 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: Get ComHasPrivateKey Of hoCert To bTemp1 If (bTemp1 = True) Begin Showln "Has private key!" Get pvComObject of hoPrivKey to vPrivKey Get ComGetPrivateKey Of hoCert vPrivKey To iSuccess // ... End Move (i + 1) To i Loop End_Procedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.