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
(DataFlex) 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.
Use ChilkatAx-win32.pkg Procedure Test Handle hoCertStore Boolean iReadOnly Boolean iSuccess String sPfxPassword Boolean iAllSuccess Integer iNumSuccess Variant vEntry Handle hoEntry Handle hoZip Variant vCertData Handle hoCertData Handle hoSbFilename Integer iNumCerts Integer i Variant vCert Handle hoCert Boolean iBHasPrivateKey String sTemp1 Boolean bTemp1 Get Create (RefClass(cComChilkatCertStore)) To hoCertStore If (Not(IsComObjectCreated(hoCertStore))) Begin Send CreateComObject of hoCertStore End Move True To iReadOnly Get ComOpenCurrentUserStore Of hoCertStore iReadOnly To iSuccess If (Not iSuccess) Begin Get ComLastErrorText Of hoCertStore To sTemp1 Showln sTemp1 Procedure_Return End Move "secret" To sPfxPassword Move True To iAllSuccess Move 0 To iNumSuccess Get Create (RefClass(cComChilkatZip)) To hoZip If (Not(IsComObjectCreated(hoZip))) Begin Send CreateComObject of hoZip End Get ComNewZip Of hoZip "qa_output/personalCerts.zip" To iSuccess Get Create (RefClass(cComChilkatBinData)) To hoCertData If (Not(IsComObjectCreated(hoCertData))) Begin Send CreateComObject of hoCertData End Get Create (RefClass(cComChilkatStringBuilder)) To hoSbFilename If (Not(IsComObjectCreated(hoSbFilename))) Begin Send CreateComObject of hoSbFilename End // Iterate over the certificates in the Current User store. Get ComNumCertificates Of hoCertStore To iNumCerts Move 0 To i While (i < iNumCerts) Get ComGetCertificate Of hoCertStore i To vCert If (IsComObject(vCert)) Begin Get Create (RefClass(cComChilkatCert)) To hoCert Set pvComObject Of hoCert To vCert End Get ComSubjectDN Of hoCert To sTemp1 Showln "DN = " sTemp1 Get ComSetString Of hoSbFilename "cert" To iSuccess Get ComAppendInt Of hoSbFilename (i + 1) To iSuccess Get ComHasPrivateKey Of hoCert To iBHasPrivateKey Get ComPrivateKeyExportable Of hoCert To bTemp1 If ((iBHasPrivateKey = True) And (bTemp1 = True)) Begin // Export to a .pfx Get pvComObject of hoCertData to vCertData Get ComExportToPfxBd Of hoCert sPfxPassword True vCertData To iSuccess If (iSuccess = True) Begin Get ComAppend Of hoSbFilename ".pfx" To iSuccess Get ComGetAsString Of hoSbFilename To sTemp1 Get pvComObject of hoCertData to vCertData Get ComAppendBd Of hoZip sTemp1 vCertData To vEntry If (IsComObject(vEntry)) Begin Get Create (RefClass(cComChilkatZipEntry)) To hoEntry Set pvComObject Of hoEntry To vEntry End Send Destroy of hoEntry End End Else Begin // Export to a .cer Get pvComObject of hoCertData to vCertData Get ComExportCertDerBd Of hoCert vCertData To iSuccess If (iSuccess = True) Begin Get ComAppend Of hoSbFilename ".cer" To iSuccess Get ComGetAsString Of hoSbFilename To sTemp1 Get pvComObject of hoCertData to vCertData Get ComAppendBd Of hoZip sTemp1 vCertData To vEntry If (IsComObject(vEntry)) Begin Get Create (RefClass(cComChilkatZipEntry)) To hoEntry Set pvComObject Of hoEntry To vEntry End Send Destroy of hoEntry End End If (iSuccess <> True) Begin Move False To iAllSuccess End Else Begin Move (iNumSuccess + 1) To iNumSuccess End Move (i + 1) To i Loop If (iNumSuccess > 0) Begin Get ComWriteZipAndClose Of hoZip To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoZip To sTemp1 Showln sTemp1 Move False To iAllSuccess End End Showln "All success = " iAllSuccess End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.