DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoDsig
Variant vSbXml
Handle hoSbXml
Variant vXmlKeyInfo
Handle hoXmlKeyInfo
String sCertBase64
Handle hoCert
String sTemp1
Boolean bTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatXmlDSig)) To hoDsig
If (Not(IsComObjectCreated(hoDsig))) Begin
Send CreateComObject of hoDsig
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbXml
If (Not(IsComObjectCreated(hoSbXml))) Begin
Send CreateComObject of hoSbXml
End
Get ComLoadFile Of hoSbXml "c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml" "utf-8" To iSuccess
If (iSuccess <> True) Begin
Showln "Failed to load XML file."
Procedure_Return
End
Get pvComObject of hoSbXml to vSbXml
Get ComLoadSignatureSb Of hoDsig vSbXml To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoDsig To sTemp1
Showln sTemp1
Procedure_Return
End
// Get the KeyInfo XML.
Get ComGetKeyInfo Of hoDsig To vXmlKeyInfo
If (IsComObject(vXmlKeyInfo)) Begin
Get Create (RefClass(cComChilkatXml)) To hoXmlKeyInfo
Set pvComObject Of hoXmlKeyInfo To vXmlKeyInfo
End
Get ComLastMethodSuccess Of hoDsig To bTemp1
If (bTemp1 <> True) Begin
Get ComLastErrorText Of hoDsig To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComGetXml Of hoXmlKeyInfo To sTemp1
Showln sTemp1
Showln "----"
// 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>
Get ComGetChildContent Of hoXmlKeyInfo "*:X509Data|*:X509Certificate" To sCertBase64
Get ComLastMethodSuccess Of hoXmlKeyInfo To bTemp1
If (bTemp1 <> True) Begin
Showln "No X509Certificate found in the KeyInfo."
Procedure_Return
End
// Load a certificate object w/ the base64.
Get Create (RefClass(cComChilkatCert)) To hoCert
If (Not(IsComObjectCreated(hoCert))) Begin
Send CreateComObject of hoCert
End
Get ComLoadFromBase64 Of hoCert sCertBase64 To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoCert To sTemp1
Showln sTemp1
Procedure_Return
End
// Examine the cert..
Get ComSubjectDN Of hoCert To sTemp1
Showln "SubjectDN: " sTemp1
Get ComIssuerDN Of hoCert To sTemp1
Showln "IssuerDN: " sTemp1
Get ComSerialDecimal Of hoCert To sTemp1
Showln "SerialNumber as Decimal: " sTemp1
Send Destroy of hoXmlKeyInfo
End_Procedure