1. Ong Chin Keat
  2. PowerBuilder
  3. Wednesday, 10 July 2024 03:43 AM UTC

hi all,

Tried look for XML Canonicalization and only solution is via C# DLL Import. However, when successful created the DLL and import into PB2022R2, the function hanged when calling the of_canonicalizexml function. Need advise what wrong with it. Hereby included the C# class library and PB script calling :

 

VS2019 C# class library :

using System;
using System.IO;
using System.Security.Cryptography.Xml;
using System.Xml;

namespace XmlCanonicalizationLibrary
{
    public class XmlCanonicalizer
    {
        public string CanonicalizeXml(string xml)
        {
            // Load the XML string into an XmlDocument
            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;
            doc.LoadXml(xml);

            // Create a new XML canonicalization transform
            XmlDsigC14NTransform c14nTransform = new XmlDsigC14NTransform();

            // Load the XmlDocument into the transform
            c14nTransform.LoadInput(doc);

            // Canonicalize and get the result as a stream
            using (Stream canonicalizedStream = (Stream)c14nTransform.GetOutput(typeof(Stream)))
            {
                StreamReader reader = new StreamReader(canonicalizedStream);
                string canonicalizedXml = reader.ReadToEnd();
                return canonicalizedXml;
            }
        }
    }
}

 

PB Script calling after successful run DLL Importer : 

nvo_xmlcanonicalizer lnvo_xmlcanon

lnvo_xmlcanon = Create nvo_xmlcanonicalizer
STRING ls_XMLbefore, ls_XMLafter

ls_XMLbefore = '<ext:UBLExtensions><ext:UBLExtension><ext:ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ext:ExtensionURI><ext:ExtensionContent><sig:UBLDocumentSignatures xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-2" xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2" xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2"><sac:SignatureInformation><cbc:ID>urn:oasis:names:specification:ubl:signature:1</cbc:ID><sbc:ReferencedSignatureID>urn:oasis:names:specification:ubl:signature:Invoice</sbc:ReferencedSignatureID><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="signature"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/2006/12/xml-c14n11"/><ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/><ds:Reference Id="id-doc-signed-data" URI=""><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116"><ds:XPath>not(//ancestor-or-self::ext:UBLExtensions)</ds:XPath></ds:Transform><ds:Transform Algorithm="http://www.w3.org/TR/1999/REC-xpath-19991116"><ds:XPath>not(//ancestor-or-self::cac:Signature)</ds:XPath></ds:Transform><ds:Transform Algorithm="http://www.w3.org/2006/12/xml-c14n11"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><ds:DigestValue>RvCSpMYz8009KbJ3ku72oaCFWpzEfQNcpc+5bulh3Jk=</ds:DigestValue></ds:Reference><ds:Reference Type="http://www.w3.org/2000/09/xmldsig#SignatureProperties" URI="#id-xades-signed-props"><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><ds:DigestValue>OGU1M2Q3NGFkOTdkYTRiNDVhOGZmYmU2ZjE0YzI3ZDhhNjlmM2EzZmQ4MTU5NTBhZjBjNDU2MWZlNjU3MWU0ZQ==</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>MEYCIQDYsDnviJYPgYjyCIYAyzETeYthIoJaQhChblP4eAAPPAIhAJl6zfHgiKmWTtsfUz8YBZ8QkQ9rBL4Uy7mK0cxvWooH</ds:SignatureValue><ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIIEQzCCAyugAwIBAgIhAOkUChItLeodmoK/A7B0XLcSUCvT4jgrSeYBOeZ1G8VPMA0GCSqGSIb3DQEBBQUAMIG9MQswCQYDVQQGEwJLTDEhMB8GA1UECgwYQ29udG9zbyBNYWxheXNpYSBTZG4gQmhkMSEwHwYDVQQLDBhDb250b3NvIE1hbGF5c2lhIFNkbiBCaGQxITAfBgNVBAMMGENvb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3pfjPb5u0c0WKnbkj5mow75TuEmc0k1qow6Z6H5O6cPhX+eyNQSFZ3QnC0W2oIZTi96TVT4JH8LOPurZ5AdG9maQNIypaZ0gYPtAJISP+nxPOHmloicecdLLaMG/cvDf2+/bJR2P98dTuTZqgKrvWHkiMOma62MVx5dbcmbxgxU6</ds:X509Certificate></ds:X509Data></ds:KeyInfo><ds:Object><xades:QualifyingProperties xmlns:xades="http://uri.etsi.org/01903/v1.3.2#" Target="signature"><xades:SignedProperties Id="id-xades-signed-props"><xades:SignedSignatureProperties><xades:SigningTime>2024-04-01T00:41:21Z</xades:SigningTime><xades:SigningCertificate><xades:Cert><xades:CertDigest><ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/><ds:DigestValue>YTJkM2JhYTcwZTBhZTAxOGYwODMyNzY3NTdkZDM3YzhjY2IxOTIyZDZhM2RlZGJiMGY0NDUzZWJhYWI4MDhmYg==</ds:DigestValue></xades:CertDigest><xades:IssuerSerial><ds:X509IssuerName>CN = Contoso Malaysia Sdn Bhd, E = noemail@contoso.com, OU = Contoso Malaysia Sdn Bhd, O = Contoso Malaysia Sdn Bhd, C = MY</ds:X509IssuerName><ds:X509SerialNumber>2475382886904809774818644480820936050208702411</ds:X509SerialNumber></xades:IssuerSerial></xades:Cert></xades:SigningCertificate></xades:SignedSignatureProperties></xades:SignedProperties></xades:QualifyingProperties></ds:Object></ds:Signature></sac:SignatureInformation></sig:UBLDocumentSignatures></ext:ExtensionContent></ext:UBLExtension></ext:UBLExtensions>'
ls_XMLafter  = lnvo_xmlcanon.of_canonicalizexml(ls_XMLbefore)

Please help.

 

regards,

Dev Ong.

 

Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 10 July 2024 16:00 PM UTC
  2. PowerBuilder
  3. # 1

Hi Ong,

If you have the source for the C# code, I suggest debugging the call and seeing where it's getting stuck. Publish the DLL on the Debug configuration, if you have SnapDevelop installed you can debug the C# code by just stepping into it from PB; if you don't you can just attach the debugger from any other IDE (you have to attach to the PB220.exe process)

 

Regards,
Francisco

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.