![]() |
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
(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. Note: This example requires Chilkat v10.1.2 or greater.
LOCAL loCertStore LOCAL lnReadOnly LOCAL lnSuccess LOCAL lcPfxPassword LOCAL lnAllSuccess LOCAL lnNumSuccess LOCAL loEntry LOCAL loZip LOCAL loCertData LOCAL loSbFilename LOCAL loCert LOCAL lnNumCerts LOCAL i 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. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Cert') loCert = CreateObject('Chilkat.Cert') lnNumCerts = loCertStore.NumCertificates i = 0 DO WHILE i < lnNumCerts loCertStore.GetCert(i,loCert) ? "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 RELEASE loCert |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.