Sample code for 30+ languages & platforms
AutoIt

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 AutoIt Downloads

AutoIt
Local $bSuccess = False

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

$oDsig = ObjCreate("Chilkat.XmlDSig")
$oSbXml = ObjCreate("Chilkat.StringBuilder")

$bSuccess = $oSbXml.LoadFile("c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml","utf-8")
If ($bSuccess <> True) Then
    ConsoleWrite("Failed to load XML file." & @CRLF)
    Exit
EndIf

$bSuccess = $oDsig.LoadSignatureSb($oSbXml)
If ($bSuccess <> True) Then
    ConsoleWrite($oDsig.LastErrorText & @CRLF)
    Exit
EndIf

; Get the KeyInfo XML.
Local $oXmlKeyInfo = $oDsig.GetKeyInfo()
If ($oDsig.LastMethodSuccess <> True) Then
    ConsoleWrite($oDsig.LastErrorText & @CRLF)
    Exit
EndIf

ConsoleWrite($oXmlKeyInfo.GetXml() & @CRLF)
ConsoleWrite("----" & @CRLF)

; 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>
Local $sCertBase64 = $oXmlKeyInfo.GetChildContent("*:X509Data|*:X509Certificate")
If ($oXmlKeyInfo.LastMethodSuccess <> True) Then
    ConsoleWrite("No X509Certificate found in the KeyInfo." & @CRLF)
    Exit
EndIf

; Load a certificate object w/ the base64.
$oCert = ObjCreate("Chilkat.Cert")
$bSuccess = $oCert.LoadFromBase64($sCertBase64)
If ($bSuccess <> True) Then
    ConsoleWrite($oCert.LastErrorText & @CRLF)
    Exit
EndIf

; Examine the cert..
ConsoleWrite("SubjectDN: " & $oCert.SubjectDN & @CRLF)
ConsoleWrite("IssuerDN: " & $oCert.IssuerDN & @CRLF)
ConsoleWrite("SerialNumber as Decimal: " & $oCert.SerialDecimal & @CRLF)