Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) Create XAdES for Malaysia E-InvoiceSee more XML Digital Signatures ExamplesThis example signs XML to create the required XAdES for Malaysia E-Invoice as described at the following web pages:
https://sdk.myinvois.hasil.gov.my/signature/
integer li_rc integer li_Success oleobject loo_XmlToSign integer li_Success oleobject loo_Gen oleobject loo_Object1 oleobject loo_Cert oleobject loo_SbXml oleobject loo_Verifier integer li_NumSigs integer li_VerifyIdx integer li_Verified // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. li_Success = 1 // See also: MyInvois Malaysia Login as Intermediary System // Load the XML invoice to sign. loo_XmlToSign = create oleobject li_rc = loo_XmlToSign.ConnectToNewObject("Chilkat_9_5_0.Xml") if li_rc < 0 then destroy loo_XmlToSign MessageBox("Error","Connecting to COM object failed") return end if li_Success = loo_XmlToSign.LoadXmlFile("c:/someDir/eInvoice.xml") if li_Success = 0 then Write-Debug loo_XmlToSign.LastErrorText destroy loo_XmlToSign return end if // Note: If you have a sample of already-signed XML, then you can copy it into Chilkat's online tool at // Generate XAdES Code // to generate the source code that would produce the signed XML. // A sample of already signed XML is made available at https://sdk.myinvois.hasil.gov.my/files/one-doc-signed.xml loo_Gen = create oleobject li_rc = loo_Gen.ConnectToNewObject("Chilkat_9_5_0.XmlDSigGen") loo_Gen.SigLocation = "Invoice|ext:UBLExtensions|ext:UBLExtension|ext:ExtensionContent|sig:UBLDocumentSignatures|sac:SignatureInformation" loo_Gen.SigLocationMod = 0 loo_Gen.SigId = "signature" loo_Gen.SigNamespacePrefix = "ds" loo_Gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#" loo_Gen.SignedInfoCanonAlg = "C14N_11" loo_Gen.SignedInfoDigestMethod = "sha256" // Create an Object to be added to the Signature. loo_Object1 = create oleobject li_rc = loo_Object1.ConnectToNewObject("Chilkat_9_5_0.Xml") loo_Object1.Tag = "xades:QualifyingProperties" loo_Object1.AddAttribute("xmlns:xades","http://uri.etsi.org/01903/v1.3.2#") loo_Object1.AddAttribute("Target","signature") loo_Object1.UpdateAttrAt("xades:SignedProperties",1,"Id","id-xades-signed-props") loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningTime","TO BE GENERATED BY CHILKAT") loo_Object1.UpdateAttrAt("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestMethod",1,"Algorithm","http://www.w3.org/2001/04/xmlenc#sha256") loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestValue","TO BE GENERATED BY CHILKAT") loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509IssuerName","TO BE GENERATED BY CHILKAT") loo_Object1.UpdateChildContent("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509SerialNumber","TO BE GENERATED BY CHILKAT") loo_Gen.AddObject("",loo_Object1.GetXml(),"","") // -------- Reference 1 -------- loo_Gen.AddSameDocRef("","sha256","C14N_11","","") loo_Gen.SetRefIdAttr("","id-doc-signed-data") // -------- Reference 2 -------- loo_Gen.AddObjectRef("id-xades-signed-props","sha256","","","http://www.w3.org/2000/09/xmldsig#SignatureProperties") // Provide a certificate + private key. (PFX password is test123) loo_Cert = create oleobject li_rc = loo_Cert.ConnectToNewObject("Chilkat_9_5_0.Cert") li_Success = loo_Cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123") if li_Success <> 1 then Write-Debug loo_Cert.LastErrorText destroy loo_XmlToSign destroy loo_Gen destroy loo_Object1 destroy loo_Cert return end if loo_Gen.SetX509Cert(loo_Cert,1) loo_Gen.KeyInfoType = "X509Data" loo_Gen.X509Type = "Certificate" // Load XML to be signed... loo_SbXml = create oleobject li_rc = loo_SbXml.ConnectToNewObject("Chilkat_9_5_0.StringBuilder") loo_XmlToSign.GetXmlSb(loo_SbXml) loo_Gen.Behaviors = "IndentedSignature,TransformSignatureXPath" // Sign the XML... li_Success = loo_Gen.CreateXmlDSigSb(loo_SbXml) if li_Success <> 1 then Write-Debug loo_Gen.LastErrorText destroy loo_XmlToSign destroy loo_Gen destroy loo_Object1 destroy loo_Cert destroy loo_SbXml return end if // ----------------------------------------------- // Save the signed XML to a file. li_Success = loo_SbXml.WriteFile("c:/temp/qa_output/signedXml.xml","utf-8",0) Write-Debug loo_SbXml.GetAsString() // ---------------------------------------- // Verify the signatures we just produced... loo_Verifier = create oleobject li_rc = loo_Verifier.ConnectToNewObject("Chilkat_9_5_0.XmlDSig") li_Success = loo_Verifier.LoadSignatureSb(loo_SbXml) if li_Success <> 1 then Write-Debug loo_Verifier.LastErrorText destroy loo_XmlToSign destroy loo_Gen destroy loo_Object1 destroy loo_Cert destroy loo_SbXml destroy loo_Verifier return end if li_NumSigs = loo_Verifier.NumSignatures li_VerifyIdx = 0 do while li_VerifyIdx < li_NumSigs loo_Verifier.Selector = li_VerifyIdx li_Verified = loo_Verifier.VerifySignature(1) if li_Verified <> 1 then Write-Debug loo_Verifier.LastErrorText destroy loo_XmlToSign destroy loo_Gen destroy loo_Object1 destroy loo_Cert destroy loo_SbXml destroy loo_Verifier return end if li_VerifyIdx = li_VerifyIdx + 1 loop Write-Debug "All signatures were successfully verified." destroy loo_XmlToSign destroy loo_Gen destroy loo_Object1 destroy loo_Cert destroy loo_SbXml destroy loo_Verifier |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.