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
(Visual FoxPro) 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.
LOCAL loCertStore LOCAL lnReadOnly LOCAL lnSuccess LOCAL lcPfxPassword LOCAL lnAllSuccess LOCAL lnNumSuccess LOCAL loEntry LOCAL loZip LOCAL loCertData LOCAL loSbFilename LOCAL lnNumCerts LOCAL i LOCAL loCert LOCAL lnBHasPrivateKey * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.CertStore') loCertStore = CreateObject('Chilkat.CertStore') lnReadOnly = 1 lnSuccess = loCertStore.OpenCurrentUserStore(lnReadOnly) IF (NOT lnSuccess) THEN ? loCertStore.LastErrorText RELEASE loCertStore CANCEL ENDIF lcPfxPassword = "secret" lnAllSuccess = 1 lnNumSuccess = 0 * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Zip') loZip = CreateObject('Chilkat.Zip') loZip.NewZip("qa_output/personalCerts.zip") * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.BinData') loCertData = CreateObject('Chilkat.BinData') * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbFilename = CreateObject('Chilkat.StringBuilder') * 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) lnBHasPrivateKey = loCert.HasPrivateKey() IF ((lnBHasPrivateKey = 1) AND (loCert.PrivateKeyExportable = 1)) THEN * Export to a .pfx lnSuccess = loCert.ExportToPfxBd(lcPfxPassword,1,loCertData) IF (lnSuccess = 1) THEN loSbFilename.Append(".pfx") loEntry = loZip.AppendBd(loSbFilename.GetAsString(),loCertData) RELEASE loEntry ENDIF ELSE * Export to a .cer lnSuccess = loCert.ExportCertDerBd(loCertData) IF (lnSuccess = 1) THEN loSbFilename.Append(".cer") loEntry = loZip.AppendBd(loSbFilename.GetAsString(),loCertData) RELEASE loEntry ENDIF ENDIF IF (lnSuccess <> 1) THEN lnAllSuccess = 0 ELSE lnNumSuccess = lnNumSuccess + 1 ENDIF i = i + 1 ENDDO IF (lnNumSuccess > 0) THEN lnSuccess = loZip.WriteZipAndClose() IF (lnSuccess <> 1) THEN ? loZip.LastErrorText lnAllSuccess = 0 ENDIF ENDIF ? "All success = " + STR(lnAllSuccess) RELEASE loCertStore RELEASE loZip RELEASE loCertData RELEASE loSbFilename |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.