Retrieving Web Certificates with CAPICOM
The following code snippet shows how to directly create a CAPICOM certificate
object from a certificate deployed from a web-server. The binary array (safearray)
object is obtained from the URL for the certificate using XMLHTTP class and the
responseBody method. This array is converted to a string with Utils.ByteArrayToBinaryString()
which is then used to initialize the certificate object with Certificate.Import. This handles
certificates in binary-DER or base64-encoded DER format (including base64 files with
enclosing "-----BEGIN/END CERTIFICATE-----" boundary lines.
The certificate object can then be imported into any store with standard CAPICOM
methods, or written to a file.
Option Explicit
Dim oHttp, oUtils, oCert, body, certStr, sSource
set oHTTP = CreateObject("Microsoft.XMLHTTP")
set oUtils = CreateObject("CAPICOM.Utilities")
set oCert = CreateObject("CAPICOM.Certificate")
sSource = "http://"
oHTTP.open "GET", sSource, False
oHTTP.send
body = oHTTP.responseBody 'safearray (byte) contents
certStr = oUtils.ByteArrayToBinaryString(body)
oCert.Import(certStr)
oCert.Display()
set oHTTP = nothing
set oUtils = nothing
set oCert = nothing
Michel I. Gallant
neutron@istar.ca