Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Backup Windows Current User / Personal Certificates to a .zipDemonstrates how to backup the certificates in the Windows registry-based Current User certificate store (in the "Personal" Logical Store as seen in certmgr.msc), to a zip archive. Certificates having an exportable private key are exported to .pfx files. Certificates with no private key, or with a non-exportable private key, are exported to .cer files. Obviously, this example only runs on Windows computers.
integer li_rc oleobject loo_CertStore integer li_ReadOnly integer li_Success string ls_PfxPassword integer li_AllSuccess integer li_NumSuccess oleobject loo_Entry oleobject loo_Zip oleobject loo_CertData oleobject loo_SbFilename integer li_NumCerts integer i oleobject loo_Cert integer li_BHasPrivateKey loo_CertStore = create oleobject // Use "Chilkat_9_5_0.CertStore" for versions of Chilkat < 10.0.0 li_rc = loo_CertStore.ConnectToNewObject("Chilkat.CertStore") if li_rc < 0 then destroy loo_CertStore MessageBox("Error","Connecting to COM object failed") return end if li_ReadOnly = 1 li_Success = loo_CertStore.OpenCurrentUserStore(li_ReadOnly) if not li_Success then Write-Debug loo_CertStore.LastErrorText destroy loo_CertStore return end if ls_PfxPassword = "secret" li_AllSuccess = 1 li_NumSuccess = 0 loo_Zip = create oleobject // Use "Chilkat_9_5_0.Zip" for versions of Chilkat < 10.0.0 li_rc = loo_Zip.ConnectToNewObject("Chilkat.Zip") loo_Zip.NewZip("qa_output/personalCerts.zip") loo_CertData = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_CertData.ConnectToNewObject("Chilkat.BinData") loo_SbFilename = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbFilename.ConnectToNewObject("Chilkat.StringBuilder") // Iterate over the certificates in the Current User store. li_NumCerts = loo_CertStore.NumCertificates i = 0 do while i < li_NumCerts loo_Cert = loo_CertStore.GetCertificate(i) Write-Debug "DN = " + loo_Cert.SubjectDN loo_SbFilename.SetString("cert") loo_SbFilename.AppendInt(i + 1) li_BHasPrivateKey = loo_Cert.HasPrivateKey() if (li_BHasPrivateKey = 1) AND (loo_Cert.PrivateKeyExportable = 1) then // Export to a .pfx li_Success = loo_Cert.ExportToPfxBd(ls_PfxPassword,1,loo_CertData) if li_Success = 1 then loo_SbFilename.Append(".pfx") loo_Entry = loo_Zip.AppendBd(loo_SbFilename.GetAsString(),loo_CertData) destroy loo_Entry end if else // Export to a .cer li_Success = loo_Cert.ExportCertDerBd(loo_CertData) if li_Success = 1 then loo_SbFilename.Append(".cer") loo_Entry = loo_Zip.AppendBd(loo_SbFilename.GetAsString(),loo_CertData) destroy loo_Entry end if end if if li_Success <> 1 then li_AllSuccess = 0 else li_NumSuccess = li_NumSuccess + 1 end if i = i + 1 loop if li_NumSuccess > 0 then li_Success = loo_Zip.WriteZipAndClose() if li_Success <> 1 then Write-Debug loo_Zip.LastErrorText li_AllSuccess = 0 end if end if Write-Debug "All success = " + string(li_AllSuccess) destroy loo_CertStore destroy loo_Zip destroy loo_CertData destroy loo_SbFilename |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.