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

PowerBuilder 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
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

 

 

 

(PowerBuilder) 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

integer li_rc
oleobject loo_CertStore
integer li_ReadOnly
integer li_Success
string ls_PfxPassword
integer li_AllSuccess
integer li_NumSuccess
oleobject loo_Entry
oleobject loo_Zip
oleobject loo_CertData
oleobject loo_SbFilename
integer li_NumCerts
integer i
oleobject loo_Cert
integer li_BHasPrivateKey

loo_CertStore = create oleobject
// Use "Chilkat_9_5_0.CertStore" for versions of Chilkat < 10.0.0
li_rc = loo_CertStore.ConnectToNewObject("Chilkat.CertStore")
if li_rc < 0 then
    destroy loo_CertStore
    MessageBox("Error","Connecting to COM object failed")
    return
end if

li_ReadOnly = 1
li_Success = loo_CertStore.OpenCurrentUserStore(li_ReadOnly)
if not li_Success then
    Write-Debug loo_CertStore.LastErrorText
    destroy loo_CertStore
    return
end if

ls_PfxPassword = "secret"

li_AllSuccess = 1
li_NumSuccess = 0

loo_Zip = create oleobject
// Use "Chilkat_9_5_0.Zip" for versions of Chilkat < 10.0.0
li_rc = loo_Zip.ConnectToNewObject("Chilkat.Zip")

loo_Zip.NewZip("qa_output/personalCerts.zip")

loo_CertData = create oleobject
// Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0
li_rc = loo_CertData.ConnectToNewObject("Chilkat.BinData")

loo_SbFilename = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbFilename.ConnectToNewObject("Chilkat.StringBuilder")

// Iterate over the certificates in the Current User store.
li_NumCerts = loo_CertStore.NumCertificates
i = 0
do while i < li_NumCerts
    loo_Cert = loo_CertStore.GetCertificate(i)
    Write-Debug "DN = " + loo_Cert.SubjectDN

    loo_SbFilename.SetString("cert")
    loo_SbFilename.AppendInt(i + 1)

    li_BHasPrivateKey = loo_Cert.HasPrivateKey()
    if (li_BHasPrivateKey = 1) AND (loo_Cert.PrivateKeyExportable = 1) then
        // Export to a .pfx
        li_Success = loo_Cert.ExportToPfxBd(ls_PfxPassword,1,loo_CertData)
        if li_Success = 1 then
            loo_SbFilename.Append(".pfx")
            loo_Entry = loo_Zip.AppendBd(loo_SbFilename.GetAsString(),loo_CertData)
            destroy loo_Entry
        end if

    else
        // Export to a .cer
        li_Success = loo_Cert.ExportCertDerBd(loo_CertData)
        if li_Success = 1 then
            loo_SbFilename.Append(".cer")
            loo_Entry = loo_Zip.AppendBd(loo_SbFilename.GetAsString(),loo_CertData)
            destroy loo_Entry
        end if

    end if

    if li_Success <> 1 then
        li_AllSuccess = 0
    else
        li_NumSuccess = li_NumSuccess + 1
    end if

    i = i + 1
loop

if li_NumSuccess > 0 then
    li_Success = loo_Zip.WriteZipAndClose()
    if li_Success <> 1 then
        Write-Debug loo_Zip.LastErrorText
        li_AllSuccess = 0
    end if

end if

Write-Debug "All success = " + string(li_AllSuccess)


destroy loo_CertStore
destroy loo_Zip
destroy loo_CertData
destroy loo_SbFilename

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.