Sample code for 30+ languages & platforms
Xbase++

Subject Alternative Name

See more Certificates Examples

Demonstrates the usage of the SubjectAlternativeName property to get the certificate SAN (subject alternative name) as XML.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oCert
LOCAL cSubjectAltNameXml
LOCAL oXml
LOCAL cOid
LOCAL cName
LOCAL i
LOCAL nCount_i
LOCAL cRfc822Name

nSuccess := 0

//  Note: Not all certificates contain a Subject Alternative Name.
//  If it does not, the SubjectAlternativeName property will contain the empty string.

oCert := CreateObject("Chilkat.Cert")

nSuccess := oCert:LoadFromFile("qa_data/certs/testIcpBrasil.cer")
IF (nSuccess == 0)
    ? oCert:LastErrorText
    oCert:destroy()
    RETURN
ENDIF

cSubjectAltNameXml := oCert:SubjectAlternativeName

? cSubjectAltNameXml

//  Here's a sample of the subjectAltNameXml:

//  <?xml version="1.0" encoding="utf-8"?>
//  <SubjectAltName>
//      <name type="oid" oid="2.16.76.1.3.4">...</name>
//      <name type="oid" oid="2.16.76.1.3.2">...</name>
//      <name type="oid" oid="2.16.76.1.3.3">...</name>
//      <name type="oid" oid="2.16.76.1.3.7">...</name>
//      <rfc822Name>...</rfc822Name>
//  </SubjectAltName>

//  The XML can be parsed like this:

oXml := CreateObject("Chilkat.Xml")

oXml:LoadXml(cSubjectAltNameXml)

i := 0
nCount_i := oXml:NumChildrenHavingTag("name")
DO WHILE i < nCount_i
    oXml:I := i
    cOid := oXml:ChilkatPath("name[i]|(oid)")
    cName := oXml:GetChildContent("name[i]")
    i := i + 1
ENDDO
cRfc822Name := oXml:GetChildContent("rfc822Name")

oCert:destroy()
oXml:destroy()