Extracts an X.509 certificate from a PKCS-7 "certs-only" certificate chain file.
VB6/VBA
Debug.Print "Testing X509_GetCertFromP7Chain ..." Dim nRet As Long Dim strListFile As String Dim strCertFile As String Dim nCerts As Long Dim iCert As Long strListFile = "bob.p7b" ' How many certificates? nCerts = X509_GetCertFromP7Chain("", strListFile, 0, 0) Debug.Print "X509_GetCertFromP7Chain(0) returns " & nCerts & " for " & strListFile ' Enumerate through them all If nCerts > 0 Then For iCert = 1 To nCerts strCertFile = "bobcert" & iCert & ".cer" nRet = X509_GetCertFromP7Chain(strCertFile, strListFile, iCert, 0) Debug.Print "X509_GetCertFromP7Chain(" & iCert & ") returns " _ & nRet & "->" & strCertFile Next End If
Output
Testing X509_GetCertFromP7Chain ... X509_GetCertFromP7Chain(0) returns 2 for bob.p7b X509_GetCertFromP7Chain(1) returns 555->bobcert1.cer X509_GetCertFromP7Chain(2) returns 495->bobcert2.cer
VB.NET
Console.WriteLine("Testing X509_GetCertFromP7Chain ...")
Dim nRet As Integer
Dim strListFile As String
Dim strCertFile As String
Dim nCerts As Integer
Dim iCert As Integer
strListFile = "bob.p7b"
' How many certificates?
nCerts = X509.GetCertFromP7Chain("", strListFile, 0)
Console.WriteLine("X509_GetCertFromP7Chain(0) returns " & nCerts & " for " & strListFile)
' Enumerate through them all
If nCerts > 0 Then
For iCert = 1 To nCerts
strCertFile = "bobcert" & iCert & ".cer"
nRet = X509.GetCertFromP7Chain(strCertFile, strListFile, iCert)
Console.WriteLine("X509_GetCertFromP7Chain(" & iCert & ") returns " _
& nRet & "->" & strCertFile)
Next
End If
[Contents]