Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Visual Basic 6.0 Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(Visual Basic 6.0) Create XAdES for Malaysia E-Invoice

See more Malaysia MyInvois Examples

This 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/
https://sdk.myinvois.hasil.gov.my/signature-creation/

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Dim v2 As Long
v2 = 1
Dim success As Long
success = 1

' Load XML such as the following to be signed:

' <?xml version="1.0" encoding="utf-8"?>
' <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2">
'     <ext:UBLExtensions>
'         <ext:UBLExtension>
'             <ext:ExtensionURI>urn:oasis:names:specification:ubl:dsig:enveloped:xades</ext:ExtensionURI>
'             <ext:ExtensionContent>
'                 <sig:UBLDocumentSignatures xmlns:sac="urn:oasis:names:specification:ubl:schema:xsd:SignatureAggregateComponents-2" xmlns:sbc="urn:oasis:names:specification:ubl:schema:xsd:SignatureBasicComponents-2" xmlns:sig="urn:oasis:names:specification:ubl:schema:xsd:CommonSignatureComponents-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>
'                     </sac:SignatureInformation>
'                 </sig:UBLDocumentSignatures>
'             </ext:ExtensionContent>
'         </ext:UBLExtension>
'     </ext:UBLExtensions>
'     <cbc:ID>IV00000105</cbc:ID>
'     <cbc:IssueDate>2024-07-06</cbc:IssueDate>
'     <cbc:IssueTime>15:06:00Z</cbc:IssueTime>
'     <cbc:InvoiceTypeCode listVersionID="1.1">1</cbc:InvoiceTypeCode>
'     <cbc:DocumentCurrencyCode>MYR</cbc:DocumentCurrencyCode>
'     <cac:BillingReference>
'         <cac:AdditionalDocumentReference>
'             <cbc:ID>IV00000105</cbc:ID>
'         </cac:AdditionalDocumentReference>
'     </cac:BillingReference>
'     <cac:Signature>
'         <cbc:ID>urn:oasis:names:specification:ubl:signature:Invoice</cbc:ID>
'         <cbc:SignatureMethod>urn:oasis:names:specification:ubl:dsig:enveloped:xades</cbc:SignatureMethod>
'     </cac:Signature>
'     <cac:AccountingSupplierParty>
'         <cac:Party>
'             <cbc:IndustryClassificationCode name="Other information technology service activities n.e.c.">62099</cbc:IndustryClassificationCode>
'             <cac:PartyIdentification>
'                 <cbc:ID schemeID="TIN">C99999999999</cbc:ID>
'             </cac:PartyIdentification>
'             <cac:PartyIdentification>
'                 <cbc:ID schemeID="BRN">200801099999</cbc:ID>
'             </cac:PartyIdentification>
'             <cac:PostalAddress>
'                 <cbc:CityName>Cheras</cbc:CityName>
'                 <cbc:PostalZone>56000</cbc:PostalZone>
'                 <cbc:CountrySubentityCode>14</cbc:CountrySubentityCode>
'                 <cac:AddressLine>
'                     <cbc:Line>A-3, 11, Jalan 2/199a,</cbc:Line>
'                 </cac:AddressLine>
'                 <cac:AddressLine>
'                     <cbc:Line>Cheras, 56000 Cheras</cbc:Line>
'                 </cac:AddressLine>
'                 <cac:AddressLine>
'                     <cbc:Line>Wilayah Persekutuan Kuala Lumpur</cbc:Line>
'                 </cac:AddressLine>
'                 <cac:Country>
'                     <cbc:IdentificationCode listAgencyID="6" listID="ISO3166-1">MYS</cbc:IdentificationCode>
'                 </cac:Country>
'             </cac:PostalAddress>
'             <cac:PartyLegalEntity>
'                 <cbc:RegistrationName>ABC SYSTEMS SERVICES</cbc:RegistrationName>
'             </cac:PartyLegalEntity>
'             <cac:Contact>
'                 <cbc:Telephone>019-626 9999</cbc:Telephone>
'                 <cbc:ElectronicMail>Info@abc.com.my</cbc:ElectronicMail>
'             </cac:Contact>
'         </cac:Party>
'     </cac:AccountingSupplierParty>
'     <cac:AccountingCustomerParty>
'         <cac:Party>
'             <cac:PartyIdentification>
'                 <cbc:ID schemeID="TIN">C99999999999</cbc:ID>
'             </cac:PartyIdentification>
'             <cac:PartyIdentification>
'                 <cbc:ID schemeID="BRN">200801099999</cbc:ID>
'             </cac:PartyIdentification>
'             <cac:PostalAddress>
'                 <cbc:CityName>Cheras</cbc:CityName>
'                 <cbc:PostalZone>56000</cbc:PostalZone>
'                 <cbc:CountrySubentityCode>14</cbc:CountrySubentityCode>
'                 <cac:AddressLine>
'                     <cbc:Line>A-3, 11, Jalan 2/199a,</cbc:Line>
'                 </cac:AddressLine>
'                 <cac:AddressLine>
'                     <cbc:Line>Cheras, 56000 Cheras</cbc:Line>
'                 </cac:AddressLine>
'                 <cac:AddressLine>
'                     <cbc:Line>Cheras, 56000 Cheras</cbc:Line>
'                 </cac:AddressLine>
'                 <cac:Country>
'                     <cbc:IdentificationCode listAgencyID="6" listID="ISO3166-1">MYS</cbc:IdentificationCode>
'                 </cac:Country>
'             </cac:PostalAddress>
'             <cac:PartyLegalEntity>
'                 <cbc:RegistrationName>ABC SYSTEMS SERVICES</cbc:RegistrationName>
'             </cac:PartyLegalEntity>
'             <cac:Contact>
'                 <cbc:Telephone>019-626 9999</cbc:Telephone>
'                 <cbc:ElectronicMail>Info@abc.com.my</cbc:ElectronicMail>
'             </cac:Contact>
'         </cac:Party>
'     </cac:AccountingCustomerParty>
'     <cac:TaxTotal>
'         <cbc:TaxAmount currencyID="MYR">0</cbc:TaxAmount>
'         <cac:TaxSubtotal>
'             <cbc:TaxableAmount currencyID="MYR">40</cbc:TaxableAmount>
'             <cbc:TaxAmount currencyID="MYR">0</cbc:TaxAmount>
'             <cac:TaxCategory>
'                 <cbc:ID>6</cbc:ID>
'                 <cbc:Percent>0</cbc:Percent>
'                 <cac:TaxScheme>
'                     <cbc:ID schemeAgencyID="6" schemeID="UN/ECE 5153">OTH</cbc:ID>
'                 </cac:TaxScheme>
'             </cac:TaxCategory>
'         </cac:TaxSubtotal>
'     </cac:TaxTotal>
'     <cac:LegalMonetaryTotal>
'         <cbc:LineExtensionAmount currencyID="MYR">40</cbc:LineExtensionAmount>
'         <cbc:TaxExclusiveAmount currencyID="MYR">40</cbc:TaxExclusiveAmount>
'         <cbc:TaxInclusiveAmount currencyID="MYR">49</cbc:TaxInclusiveAmount>
'         <cbc:AllowanceTotalAmount currencyID="MYR">0</cbc:AllowanceTotalAmount>
'         <cbc:PayableAmount currencyID="MYR">49</cbc:PayableAmount>
'     </cac:LegalMonetaryTotal>
'     <cac:InvoiceLine>
'         <cbc:ID>1</cbc:ID>
'         <cbc:InvoicedQuantity unitCode="H87">2</cbc:InvoicedQuantity>
'         <cbc:LineExtensionAmount currencyID="MYR">40</cbc:LineExtensionAmount>
'         <cac:TaxTotal>
'             <cbc:TaxAmount currencyID="MYR">0</cbc:TaxAmount>
'             <cac:TaxSubtotal>
'                 <cbc:TaxableAmount currencyID="MYR">40</cbc:TaxableAmount>
'                 <cbc:TaxAmount currencyID="MYR">0</cbc:TaxAmount>
'                 <cac:TaxCategory>
'                     <cbc:ID>6</cbc:ID>
'                     <cbc:Percent>0</cbc:Percent>
'                     <cac:TaxScheme>
'                         <cbc:ID schemeAgencyID="6" schemeID="UN/ECE 5153">OTH</cbc:ID>
'                     </cac:TaxScheme>
'                 </cac:TaxCategory>
'             </cac:TaxSubtotal>
'         </cac:TaxTotal>
'         <cac:Item>
'             <cbc:Description>Computer Monitor 24 inch</cbc:Description>
'             <cac:CommodityClassification>
'                 <cbc:ItemClassificationCode listID="CLASS">3</cbc:ItemClassificationCode>
'             </cac:CommodityClassification>
'         </cac:Item>
'         <cac:Price>
'             <cbc:PriceAmount currencyID="MYR">20</cbc:PriceAmount>
'         </cac:Price>
'         <cac:ItemPriceExtension>
'             <cbc:Amount currencyID="MYR">40</cbc:Amount>
'         </cac:ItemPriceExtension>
'     </cac:InvoiceLine>
' </Invoice>

Dim xmlToSign As New ChilkatXml
success = xmlToSign.LoadXmlFile("qa_data/xml/myinvois_notYetSigned.xml")
If (success = 0) Then
    Debug.Print "Failed to load the XML to be signed."
    Exit Sub
End If

Dim gen As New ChilkatXmlDSigGen

gen.SigLocation = "Invoice|ext:UBLExtensions|ext:UBLExtension|ext:ExtensionContent|sig:UBLDocumentSignatures|sac:SignatureInformation"
gen.SigLocationMod = 0
gen.SigId = "signature"
gen.SigNamespacePrefix = "ds"
gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#"
gen.SignedInfoCanonAlg = "C14N"
gen.SignedInfoDigestMethod = "sha256"

' Create an Object to be added to the Signature.
Dim object1 As New ChilkatXml
object1.Tag = "xades:QualifyingProperties"
success = object1.AddAttribute("xmlns:xades","http://uri.etsi.org/01903/v1.3.2#")
success = object1.AddAttribute("Target","signature")
success = object1.UpdateAttrAt("xades:SignedProperties",1,"Id","id-xades-signed-props")
object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningTime","TO BE GENERATED BY CHILKAT"
success = object1.UpdateAttrAt("xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestMethod",1,"Algorithm","http://www.w3.org/2001/04/xmlenc#sha256")
object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:CertDigest|ds:DigestValue","TO BE GENERATED BY CHILKAT"
object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509IssuerName","TO BE GENERATED BY CHILKAT"
object1.UpdateChildContent "xades:SignedProperties|xades:SignedSignatureProperties|xades:SigningCertificate|xades:Cert|xades:IssuerSerial|ds:X509SerialNumber","TO BE GENERATED BY CHILKAT"

success = gen.AddObject("",object1.GetXml(),"","")

' -------- Reference 1 --------
Dim xml1 As New ChilkatXml
xml1.Tag = "ds:Transforms"
success = xml1.UpdateAttrAt("ds:Transform",1,"Algorithm","http://www.w3.org/TR/1999/REC-xpath-19991116")
xml1.UpdateChildContent "ds:Transform|ds:XPath","not(//ancestor-or-self::ext:UBLExtensions)"
success = xml1.UpdateAttrAt("ds:Transform[1]",1,"Algorithm","http://www.w3.org/TR/1999/REC-xpath-19991116")
xml1.UpdateChildContent "ds:Transform[1]|ds:XPath","not(//ancestor-or-self::cac:Signature)"
success = xml1.UpdateAttrAt("ds:Transform[2]",1,"Algorithm","http://www.w3.org/TR/2001/REC-xml-c14n-20010315")

success = gen.AddSameDocRef2("","sha256",xml1,"")
success = gen.SetRefIdAttr("","id-doc-signed-data")

' -------- Reference 2 --------
success = gen.AddObjectRef("id-xades-signed-props","sha256","","","http://www.w3.org/2000/09/xmldsig#SignatureProperties")

' Provide a certificate + private key. (PFX password is test123)
Dim cert As New ChilkatCert
success = cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123")
If (success <> 1) Then
    Debug.Print cert.LastErrorText
    Exit Sub
End If

success = gen.SetX509Cert(cert,1)

gen.KeyInfoType = "X509Data"
gen.X509Type = "Certificate"

' Load XML to be signed...
Dim sbXml As New ChilkatStringBuilder
success = xmlToSign.GetXmlSb(sbXml)

gen.Behaviors = "IndentedSignature,TransformSignatureXPath"

' Sign the XML...
success = gen.CreateXmlDSigSb(sbXml)
If (success <> 1) Then
    Debug.Print gen.LastErrorText
    Exit Sub
End If

' -----------------------------------------------

' Save the signed XML to a file.
success = sbXml.WriteFile("c:/temp/qa_output/signedXml.xml","utf-8",0)

Debug.Print sbXml.GetAsString()

' ----------------------------------------
' Verify the signatures we just produced...
Dim verifier As New ChilkatXmlDSig
success = verifier.LoadSignatureSb(sbXml)
If (success <> 1) Then
    Debug.Print verifier.LastErrorText
    Exit Sub
End If

Dim numSigs As Long
numSigs = verifier.NumSignatures
Dim verifyIdx As Long
verifyIdx = 0
Do While verifyIdx < numSigs
    verifier.Selector = verifyIdx
    Dim verified As Long
    verified = verifier.VerifySignature(1)
    If (verified <> 1) Then
        Debug.Print verifier.LastErrorText
        Exit Sub
    End If

    verifyIdx = verifyIdx + 1
Loop
Debug.Print "All signatures were successfully verified."

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.