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
(Lianja) 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.
loCertStore = createobject("CkCertStore") llReadOnly = .T. llSuccess = loCertStore.OpenCurrentUserStore(llReadOnly) if (not llSuccess) then ? loCertStore.LastErrorText release loCertStore return endif lcPfxPassword = "secret" llAllSuccess = .T. lnNumSuccess = 0 loZip = createobject("CkZip") loZip.NewZip("qa_output/personalCerts.zip") loCertData = createobject("CkBinData") loSbFilename = createobject("CkStringBuilder") // Iterate over the certificates in the Current User store. lnNumCerts = loCertStore.NumCertificates i = 0 do while i < lnNumCerts loCert = loCertStore.GetCertificate(i) ? "DN = " + loCert.SubjectDN loSbFilename.SetString("cert") loSbFilename.AppendInt(i + 1) llBHasPrivateKey = loCert.HasPrivateKey() if ((llBHasPrivateKey = .T.) and (loCert.PrivateKeyExportable = .T.)) then // Export to a .pfx llSuccess = loCert.ExportToPfxBd(lcPfxPassword,.T.,loCertData) if (llSuccess = .T.) then loSbFilename.Append(".pfx") loEntry = loZip.AppendBd(loSbFilename.GetAsString(),loCertData) release loEntry endif else // Export to a .cer llSuccess = loCert.ExportCertDerBd(loCertData) if (llSuccess = .T.) then loSbFilename.Append(".cer") loEntry = loZip.AppendBd(loSbFilename.GetAsString(),loCertData) release loEntry endif endif if (llSuccess <> .T.) then llAllSuccess = .F. else lnNumSuccess = lnNumSuccess + 1 endif i = i + 1 enddo if (lnNumSuccess > 0) then llSuccess = loZip.WriteZipAndClose() if (llSuccess <> .T.) then ? loZip.LastErrorText llAllSuccess = .F. endif endif ? "All success = " + str(llAllSuccess) release loCertStore release loZip release loCertData release loSbFilename |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.