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

Visual FoxPro 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

 

 

 

(Visual FoxPro) 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

LOCAL loCertStore
LOCAL lnReadOnly
LOCAL lnSuccess
LOCAL lcPfxPassword
LOCAL lnAllSuccess
LOCAL lnNumSuccess
LOCAL loEntry
LOCAL loZip
LOCAL loCertData
LOCAL loSbFilename
LOCAL lnNumCerts
LOCAL i
LOCAL loCert
LOCAL lnBHasPrivateKey

loCertStore = CreateObject('Chilkat_9_5_0.CertStore')

lnReadOnly = 1
lnSuccess = loCertStore.OpenCurrentUserStore(lnReadOnly)
IF (NOT lnSuccess) THEN
    ? loCertStore.LastErrorText
    RELEASE loCertStore
    CANCEL
ENDIF

lcPfxPassword = "secret"

lnAllSuccess = 1
lnNumSuccess = 0

loZip = CreateObject('Chilkat_9_5_0.Zip')
loZip.NewZip("qa_output/personalCerts.zip")

loCertData = CreateObject('Chilkat_9_5_0.BinData')
loSbFilename = CreateObject('Chilkat_9_5_0.StringBuilder')

*  Iterate over the certificates in the Current User store.
lnNumCerts = loCertStore.NumCertificates
i = 0
DO WHILE i < lnNumCerts
    loCert = loCertStore.GetCertificate(i)
    ? "DN = " + loCert.SubjectDN

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

    lnBHasPrivateKey = loCert.HasPrivateKey()
    IF ((lnBHasPrivateKey = 1) AND (loCert.PrivateKeyExportable = 1)) THEN
        *  Export to a .pfx
        lnSuccess = loCert.ExportToPfxBd(lcPfxPassword,1,loCertData)
        IF (lnSuccess = 1) THEN
            loSbFilename.Append(".pfx")
            loEntry = loZip.AppendBd(loSbFilename.GetAsString(),loCertData)
            RELEASE loEntry
        ENDIF

    ELSE
        *  Export to a .cer
        lnSuccess = loCert.ExportCertDerBd(loCertData)
        IF (lnSuccess = 1) THEN
            loSbFilename.Append(".cer")
            loEntry = loZip.AppendBd(loSbFilename.GetAsString(),loCertData)
            RELEASE loEntry
        ENDIF

    ENDIF

    IF (lnSuccess <> 1) THEN
        lnAllSuccess = 0
    ELSE
        lnNumSuccess = lnNumSuccess + 1
    ENDIF

    i = i + 1
ENDDO

IF (lnNumSuccess > 0) THEN
    lnSuccess = loZip.WriteZipAndClose()
    IF (lnSuccess <> 1) THEN
        ? loZip.LastErrorText
        lnAllSuccess = 0
    ENDIF

ENDIF

? "All success = " + STR(lnAllSuccess)

RELEASE loCertStore
RELEASE loZip
RELEASE loCertData
RELEASE loSbFilename


 

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