Sample code for 30+ languages & platforms
Visual FoxPro

Examine KeyInfo Certificate in XML Signature

See more XML Digital Signatures Examples

This example loads signed XML and gets the signing certificate, assuming the certificate is contained in X509Certificate within the KeyInfo.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loDsig
LOCAL loSbXml
LOCAL loXmlKeyInfo
LOCAL lcCertBase64
LOCAL loCert

lnSuccess = 0

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

loDsig = CreateObject('Chilkat.XmlDSig')
loSbXml = CreateObject('Chilkat.StringBuilder')

lnSuccess = loSbXml.LoadFile("c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml","utf-8")
IF (lnSuccess <> 1) THEN
    ? "Failed to load XML file."
    RELEASE loDsig
    RELEASE loSbXml
    CANCEL
ENDIF

lnSuccess = loDsig.LoadSignatureSb(loSbXml)
IF (lnSuccess <> 1) THEN
    ? loDsig.LastErrorText
    RELEASE loDsig
    RELEASE loSbXml
    CANCEL
ENDIF

* Get the KeyInfo XML.
loXmlKeyInfo = loDsig.GetKeyInfo()
IF (loDsig.LastMethodSuccess <> 1) THEN
    ? loDsig.LastErrorText
    RELEASE loDsig
    RELEASE loSbXml
    CANCEL
ENDIF

? loXmlKeyInfo.GetXml()
? "----"

* Assuming the X509Certificate is in the KeyInfo, it will look like this:

*   <ds:KeyInfo Id="...">
*     <ds:KeyValue>
*     ...  
*     <ds:X509Data>
*       <ds:X509Certificate>MIIHAz...</ds:X509Certificate>
*     </ds:X509Data>
*   </ds:KeyInfo>
lcCertBase64 = loXmlKeyInfo.GetChildContent("*:X509Data|*:X509Certificate")
IF (loXmlKeyInfo.LastMethodSuccess <> 1) THEN
    ? "No X509Certificate found in the KeyInfo."
    RELEASE loDsig
    RELEASE loSbXml
    CANCEL
ENDIF

* Load a certificate object w/ the base64.
loCert = CreateObject('Chilkat.Cert')
lnSuccess = loCert.LoadFromBase64(lcCertBase64)
IF (lnSuccess <> 1) THEN
    ? loCert.LastErrorText
    RELEASE loDsig
    RELEASE loSbXml
    RELEASE loCert
    CANCEL
ENDIF

* Examine the cert..
? "SubjectDN: " + loCert.SubjectDN
? "IssuerDN: " + loCert.IssuerDN
? "SerialNumber as Decimal: " + loCert.SerialDecimal

RELEASE loXmlKeyInfo

RELEASE loDsig
RELEASE loSbXml
RELEASE loCert