Sample code for 30+ languages & platforms
VBScript

Load PFX/P12 File into Certificate Store Object

Demonstrates how to load a .pfx/.p12 into a certificate store object.

Chilkat VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

set certStore = CreateObject("Chilkat.CertStore")

' This only loads the contents of the PFX file into the certStore object.
' It is not importing the PFX into the Windows certificate stores.
pfxPassword = "badssl.com"
success = certStore.LoadPfxFile("qa_data/pfx/badssl.com-client.p12",pfxPassword)
If (success = 0) Then
    outFile.WriteLine(certStore.LastErrorText)
    WScript.Quit
End If

' Examine each certificate (loaded from the PFX) in this certStore object
set cert = CreateObject("Chilkat.Cert")
numCerts = certStore.NumCertificates
i = 0
Do While i < numCerts
    success = certStore.GetCert(i,cert)
    outFile.WriteLine("hasPrivateKey=" & cert.HasPrivateKey() & ", " & cert.SubjectCN)
    i = i + 1
Loop

outFile.Close