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

PowerBuilder 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

 

 

 

(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
li_rc = loo_CertStore.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_Zip.ConnectToNewObject("Chilkat_9_5_0.Zip")

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

loo_CertData = create oleobject
li_rc = loo_CertData.ConnectToNewObject("Chilkat_9_5_0.BinData")

loo_SbFilename = create oleobject
li_rc = loo_SbFilename.ConnectToNewObject("Chilkat_9_5_0.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-2019 Chilkat Software, Inc. All Rights Reserved.