VBScript Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

VBScript Examples

Bounced Mail
Bz2
Character Encoding
Digital Certificates
CSV
Digital Signatures
Email
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
PFX
RSA
S/MIME
SFTP
SMTP
Socket
Spider
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression
Self-Extractor

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
Byte Array
RSS
Atom
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

 

Extract Public/Private Keys and Certs from PFX into String Variables

Demonstrates how to export certificates and public/private keys from a PFX file into in-memory strings.

Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set outFile = fso.CreateTextFile("output.txt", True)


set certStore = CreateObject("Chilkat.CertStore")

'  Load the PFX file into a certificate store object

password = "*myPassword2*"
success = certStore.LoadPfxFile("chilkat.pfx",password)
If (success <> 1) Then
    MsgBox certStore.LastErrorText
    WScript.Quit
End If

numCerts = certStore.NumCertificates

'  Loop over each certificate in the PFX.

For i = 0 To numCerts - 1

    Set cert = certStore.GetCertificate(i)

    outFile.WriteLine(cert.SubjectDN)
    outFile.WriteLine("---")

    encodedCert = cert.GetEncoded()

    '  This string may now be stored in a relational database string field.
    '  To re-create the cert, do this:
    set cert2 = CreateObject("Chilkat.Cert")
    cert2.SetFromEncoded encodedCert

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

        '  Get the private key.

        Set pvkey = cert.ExportPrivateKey()

        '  The private key can be exported into
        '  a string in PKCS8, RSA PEM, or XML format:

        pemPvKey = pvkey.GetRsaPem()
        pkcs8PvKey = pvkey.GetPkcs8Pem()
        xmlPvKey = pvkey.GetXml()

        outFile.WriteLine(pemPvKey)
        outFile.WriteLine(pkcs8PvKey)
        outFile.WriteLine(xmlPvKey)

        '  Any of these formatted strings may
        '  be stored in a relational database field.
        '  to restore, call LoadPem or LoadXml
        '  LoadPem accepts either RSA PEM or
        '  PKCS8 PEM:
        set pvKey2 = CreateObject("Chilkat.PrivateKey")

        pvKey2.LoadPem pemPvKey
        pvKey2.LoadPem pkcs8PvKey
        pvKey2.LoadXml xmlPvKey

    End If

    '  Now for the public key:

    Set pubkey = cert.ExportPublicKey()

    '  It can be exported to a string as OpenSSL PEM
    '  or XML:

    pubKeyPem = pubkey.GetOpenSslPem()
    pubKeyXml = pubkey.GetXml()

    outFile.WriteLine(pubKeyPem)
    outFile.WriteLine(pubKeyXml)

    '  To re-load a PublicKey object, call LoadXml
    '  or LoadOpenSslPem:
    set pubKey2 = CreateObject("Chilkat.PublicKey")

    pubKey2.LoadOpenSslPem pubKeyPem
    pubKey2.LoadXml pubKeyXml
    fname = "pubkey" & CStr(i) & "_openSsl.der"
    pubkey.SaveOpenSslDerFile 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.

outFile.Close

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

Mail Component · XML Parser