Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
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
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

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