Visual Basic Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

VB Examples

Bounced Mail
Character Encoding
Digital Certificates
Digital Signatures
Email
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
RSA Encryption
S/MIME
Socket
Spider
String
Tar
Unicode
Upload
XML
XMP
Zip Compression

More Examples...
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor


VB Strings
VB Byte Array

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

Export certificates and public/private keys from a PFX

Demonstrates how to export certificates and public/private keys from a PFX file.

Dim success As Long
Dim certStore As New ChilkatCertStore

'  Load the PFX file into a certificate store object
Dim password As String
password = "myPassword"
success = certStore.LoadPfxFile("chilkat.pfx",password)
If (success <> 1) Then
    MsgBox certStore.LastErrorText
    Exit Sub
End If

Dim i As Long
Dim numCerts As Long
numCerts = certStore.NumCertificates

Dim cert As ChilkatCert
Dim fname As String
For i = 0 To numCerts - 1

    Set cert = certStore.GetCertificate(i)

    Text1.Text = Text1.Text & cert.SubjectDN & vbCrLf
    Text1.Refresh
    Text1.Text = Text1.Text & "---" & vbCrLf
    Text1.Refresh

    '  Save the cert in DER format:
    fname = "cert" & CStr(i) & ".der"
    cert.ExportCertDerFile fname

    '  Save the cert in PEM format:
    fname = "cert" & CStr(i) & ".pem"
    cert.ExportCertPemFile fname

    '  Does this cert have a private key?
    If (cert.HasPrivateKey() = 1) Then

        '  Get the private key.
        Dim pvkey As PrivateKey
        Set pvkey = cert.ExportPrivateKey()

        '  Save the private key to a PKCS8 DER-encoded file
        fname = "pvkey" & CStr(i) & "_pkcs8.der"
        pvkey.SavePkcs8File fname

        '  Save the private key to a PKCS8 PEM-encoded file
        fname = "pvkey" & CStr(i) & "_pkcs8.pem"
        pvkey.SavePkcs8PemFile fname

        '  Save the private key to a RSA DER-encoded file
        fname = "pvkey" & CStr(i) & "_rsa.der"
        pvkey.SaveRsaDerFile fname

        '  Save the private key to a RSA PEM-encoded file
        fname = "pvkey" & CStr(i) & "_rsa.pem"
        pvkey.SaveRsaPemFile fname

        '  Save the private key to an XML file
        '  This format is Chilkat-specific, but easily parsed,
        '  making it easy to get the modulus, exponent,
        '  P, Q, DP, DQ, InverseQ, and D.
        fname = "pvkey" & CStr(i) & ".xml"
        pvkey.SaveXmlFile fname

    End If

    '  Now get the public key and save it to various file formats:
    Dim pubkey As PublicKey
    Set pubkey = cert.ExportPublicKey()

    '  Save to an OpenSSL DER format file:
    fname = "pubkey" & CStr(i) & "_openSsl.der"
    pubkey.SaveOpenSslDerFile fname

    '  Save to an OpenSSL PEM format file:
    fname = "pubkey" & CStr(i) & "_openSsl.pem"
    pubkey.SaveOpenSslPemFile fname

    '  Save to an RSA DER format file:
    fname = "pubkey" & CStr(i) & "_rsa.der"
    pubkey.SaveRsaDerFile fname

    '  Save to an XML file:
    '  This format is Chilkat-specific, but easily parsed,
    '  making it easy to get the modulus and exponent.
    fname = "pubkey" & CStr(i) & ".xml"
    pubkey.SaveXmlFile fname

Next

'  The Chilkat Certificate, Certificate Store, Private Key,
'  Public Key, and Key Container classes / objects are freeware.

'  They are used by and included with the Chilkat Email,
'  Crypt, S/MIME, and other commercial Chilkat components.

Need a specific example? Send a request to support@chilkatsoft.com

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