Sample code for 30+ languages & platforms
Visual FoxPro

Get Certificates within XML Signature

See more XML Digital Signatures Examples

Demonstrates how to get the certificates contained within an XML signature.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loSbXml
LOCAL loDsig
LOCAL i
LOCAL loSaCerts
LOCAL loCert
LOCAL lnBVerifyReferenceDigests
LOCAL lnBVerified
LOCAL j

lnSuccess = 0

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loSbXml = CreateObject('Chilkat.StringBuilder')

* Load XML containing one or more signatures.
lnSuccess = loSbXml.LoadFile("qa_data/xml_dsig_valid_samples/multipleSigners/sp.pdf.XAdES.xml","utf-8")
IF (lnSuccess = 0) THEN
    ? "Failed to load the XML file.."
    RELEASE loSbXml
    CANCEL
ENDIF

loDsig = CreateObject('Chilkat.XmlDSig')

* First load the XML containing the signatures to be verified.
* Note that this particular Signature already contains the RSA public key that will be used
* for verification.
lnSuccess = loDsig.LoadSignatureSb(loSbXml)
IF (lnSuccess <> 1) THEN
    ? loDsig.LastErrorText
    RELEASE loSbXml
    RELEASE loDsig
    CANCEL
ENDIF

* For each signature, verify and also get the certificate(s) contained within each Signature.
i = 0
loSaCerts = CreateObject('Chilkat.StringArray')
loCert = CreateObject('Chilkat.Cert')

? "numSignatures = " + STR(loDsig.NumSignatures)

DO WHILE i < loDsig.NumSignatures
    * Select the Nth signature by setting the Selector property.
    loDsig.Selector = i

    lnBVerifyReferenceDigests = 1
    lnBVerified = loDsig.VerifySignature(lnBVerifyReferenceDigests)
    ? "Signature " + STR(i + 1) + " verified = " + STR(lnBVerified)

    * Get the certificates embedded in this signature.
    loSaCerts.Clear()
    lnSuccess = loDsig.GetCerts(loSaCerts)
    IF (lnSuccess = 1) THEN
        j = 0
        DO WHILE j < loSaCerts.Count
            lnSuccess = loCert.LoadFromBase64(loSaCerts.GetString(j))
            IF (lnSuccess = 1) THEN
                ? "    " + loCert.SubjectDN
            ENDIF

            j = j + 1
        ENDDO
    ENDIF

    i = i + 1
ENDDO

RELEASE loSbXml
RELEASE loDsig
RELEASE loSaCerts
RELEASE loCert