Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

DataFlex Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(DataFlex) Backup Windows Current User / Personal Certificates to a .zip

Demonstrates 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.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-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-2019 Chilkat Software, Inc. All Rights Reserved.