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

 

 

 

 

 

 

 

Export Certificate and Private Key to PFX

Demonstrates how to export a digital certificate, it's private key, and potentially all certificates in the chain of authentication to a PFX file.

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



'  This object is used to create a certificate store object.
set ccs = CreateObject("Chilkat.CreateCS")

'  Open the local machine certificate store read-only.
ccs.ReadOnly = 1
Set certStore = ccs.OpenLocalSystemStore()

'  Can we find a certificate by email address?

Set cert = certStore.FindCertBySubjectE("admin@chilkatsoft.com")
If (cert Is Nothing ) Then
    '  Open the current-user certificate store and check it instead.

    outFile.WriteLine("Checking current-user certificate store...")

    Set certStore = ccs.OpenCurrentUserStore()

    Set cert = certStore.FindCertBySubjectE("admin@chilkatsoft.com")
    If (cert Is Nothing ) Then
        outFile.WriteLine("Failed to find certificate!")
        WScript.Quit
    End If

End If

'  Does this certificate have a private key accessible
'  to the calling process?  Private keys are *not* stored
'  within the certificate store.  Private keys are stored
'  in a key container in a Windows protected store.  It
'  can be one of two protected stores: the protected store for
'  the current logged-in user account, or the "machine-key"
'  protected store.  The private key must both exist in a
'  protected store, and the process must have permission to
'  access it...

'  You can only export to a PFX if the private key exists
'  and is accessible.

If (cert.HasPrivateKey() = 1) Then

    '  Export to a PFX.
    '  Provide a password that will be required whenever the PFX is opened.
    '  Also, include all certs in the chain of authentication.

    bIncludeChain = 1
    success = cert.ExportToPfxFile("myCert.pfx","myPassword",bIncludeChain)
    If (success <> 1) Then
        outFile.WriteLine(cert.LastErrorText)
    Else
        outFile.WriteLine("Exported to PFX!")
    End If

Else
    outFile.WriteLine("Certificate does not have a private key available")
End If

'  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