![]() |
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
(PowerBuilder) Iterate Keys and Certs in PEMDemonstrates how to access each of the private keys and certs contained within a PEM. Note: This example requires Chilkat v11.0.0 or greater.
integer li_rc integer li_Success oleobject loo_Pem string ls_Password string ls_PemContent integer li_NumPrivateKeys integer i oleobject loo_PrivKey oleobject loo_Cert integer li_NumCerts li_Success = 0 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Pem = create oleobject li_rc = loo_Pem.ConnectToNewObject("Chilkat.Pem") if li_rc < 0 then destroy loo_Pem MessageBox("Error","Connecting to COM object failed") return end if // Load the PEM from a file. // If the PEM is encrypted, provide a password. Otherwise pass an empty string for the password. ls_Password = "myPassword" li_Success = loo_Pem.LoadPemFile("../myPemFiles/myPem.pem",ls_Password) if li_Success = 0 then Write-Debug loo_Pem.LastErrorText destroy loo_Pem return end if // Note: If the app already has the PEM pre-loaded in a string variable, then load it // by calling LoadPem instead. ls_PemContent = "... the PEM contents ..." li_Success = loo_Pem.LoadPem(ls_PemContent,ls_Password) // Check for success as before.. // Iterate over the private keys. li_NumPrivateKeys = loo_Pem.NumPrivateKeys i = 0 loo_PrivKey = create oleobject li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey") do while i < li_NumPrivateKeys loo_Pem.PrivateKeyAt(i,loo_PrivKey) Write-Debug "Private Key " + string(i) + " is " + string(loo_PrivKey.BitLength) + " in length" i = i + 1 loop // Iterate over the certificates. loo_Cert = create oleobject li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert") li_NumCerts = loo_Pem.NumCerts i = 0 do while i < li_NumCerts loo_Pem.CertAt(i,loo_Cert) Write-Debug "Certificate " + string(i) + " : " + loo_Cert.SubjectDN i = i + 1 loop destroy loo_Pem destroy loo_PrivKey destroy loo_Cert |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.