Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Dsig
oleobject loo_SbXml
oleobject loo_XmlKeyInfo
string ls_CertBase64
oleobject loo_Cert

li_Success = 0

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

loo_Dsig = create oleobject
li_rc = loo_Dsig.ConnectToNewObject("Chilkat.XmlDSig")
if li_rc < 0 then
    destroy loo_Dsig
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_SbXml = create oleobject
li_rc = loo_SbXml.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_SbXml.LoadFile("c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml","utf-8")
if li_Success <> 1 then
    Write-Debug "Failed to load XML file."
    destroy loo_Dsig
    destroy loo_SbXml
    return
end if

li_Success = loo_Dsig.LoadSignatureSb(loo_SbXml)
if li_Success <> 1 then
    Write-Debug loo_Dsig.LastErrorText
    destroy loo_Dsig
    destroy loo_SbXml
    return
end if

// Get the KeyInfo XML.
loo_XmlKeyInfo = loo_Dsig.GetKeyInfo()
if loo_Dsig.LastMethodSuccess <> 1 then
    Write-Debug loo_Dsig.LastErrorText
    destroy loo_Dsig
    destroy loo_SbXml
    return
end if

Write-Debug loo_XmlKeyInfo.GetXml()
Write-Debug "----"

// 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>
ls_CertBase64 = loo_XmlKeyInfo.GetChildContent("*:X509Data|*:X509Certificate")
if loo_XmlKeyInfo.LastMethodSuccess <> 1 then
    Write-Debug "No X509Certificate found in the KeyInfo."
    destroy loo_Dsig
    destroy loo_SbXml
    return
end if

// Load a certificate object w/ the base64.
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")

li_Success = loo_Cert.LoadFromBase64(ls_CertBase64)
if li_Success <> 1 then
    Write-Debug loo_Cert.LastErrorText
    destroy loo_Dsig
    destroy loo_SbXml
    destroy loo_Cert
    return
end if

// Examine the cert..
Write-Debug "SubjectDN: " + loo_Cert.SubjectDN
Write-Debug "IssuerDN: " + loo_Cert.IssuerDN
Write-Debug "SerialNumber as Decimal: " + loo_Cert.SerialDecimal

destroy loo_XmlKeyInfo


destroy loo_Dsig
destroy loo_SbXml
destroy loo_Cert