Introduction
This page provides sample content on how to generate a signed version of a JSON document. This is assuming that the certificate has already been generated and is available as per the guidance provided here Digital Signing Certificate Profile
Note: the code shown on this page is not production ready and hence not optimized for performance and is also missing errors and exceptions handling, please make sure you handle these points in your production ready code.
The following represents the steps required to be performed to generate the final signed JSON document including the sample of the document. The steps assume that the input document is as per provided below.
{
"_D": "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2",
"_A": "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2",
"_B": "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2",
"Invoice": [{
"ID": [{
"_": "705725225958"
}
],
"IssueDate": [{
"_": "2024-06-27"
}
],
"IssueTime": [{
"_": "13:22:00Z"
}
],
"InvoiceTypeCode": [{
"_": "01",
"listVersionID": "1.1"
}
],
"DocumentCurrencyCode": [{
"_": "MYR"
}
],
"InvoicePeriod": [{
"StartDate": [{
"_": ""
}
],
"EndDate": [{
"_": ""
}
],
"Description": [{
"_": ""
}
]
}
],
"BillingReference": [{
"AdditionalDocumentReference": [{
"ID": [{
"_": "1234"
}
]
}
]
}
],
"AdditionalDocumentReference": [{
"ID": [{
"_": "762673792005"
}
]
}
],
"AccountingSupplierParty": [{
"AdditionalAccountID": [{
"_": "",
"schemeAgencyName": "CertEx"
}
],
"Party": [{
"IndustryClassificationCode": [{
"_": "61902",
"name": "Provision of telecommunications services over existing telecom connection"
}
],
"PartyIdentification": [{
"ID": [{
"_": "C1234567890",
"schemeID": "TIN"
}
]
}, {
"ID": [{
"_": "1234567890",
"schemeID": "BRN"
}
]
}, {
"ID": [{
"_": "02332234234343",
"schemeID": "SST"
}
]
}, {
"ID": [{
"_": "03434234342343432",
"schemeID": "TTX"
}
]
}
],
"PostalAddress": [{
"CityName": [{
"_": "ASAJAYA"
}
],
"PostalZone": [{
"_": "94600"
}
],
"CountrySubentityCode": [{
"_": "01"
}
],
"AddressLine": [{
"Line": [{
"_": "Line 1"
}
]
}, {
"Line": [{
"_": "Line 2"
}
]
}, {
"Line": [{
"_": "Line 3"
}
]
}
],
"Country": [{
"IdentificationCode": [{
"_": "MYS",
"listID": "3166-1",
"listAgencyID": "ISO"
}
]
}
]
}
],
"PartyLegalEntity": [{
"RegistrationName": [{
"_": "KXXX_XXXXDN BHD"
}
]
}
],
"Contact": [{
"Telephone": [{
"_": "0326162888"
}
],
"ElectronicMail": [{
"_": "noreply@email.com"
}
]
}
]
}
]
}
],
"AccountingCustomerParty": [{
"Party": [{
"PartyIdentification": [{
"ID": [{
"_": "C1234567890",
"schemeID": "TIN"
}
]
}, {
"ID": [{
"_": "1234567890",
"schemeID": "BRN"
}
]
}
],
"PostalAddress": [{
"CityName": [{
"_": "SEMUA NEGERI"
}
],
"PostalZone": [{
"_": "81500"
}
],
"CountrySubentityCode": [{
"_": "00"
}
],
"AddressLine": [{
"Line": [{
"_": "buyerAddressLine1"
}
]
}, {
"Line": [{
"_": "buyerAddressLine2"
}
]
}, {
"Line": [{
"_": ""
}
]
}
],
"Country": [{
"IdentificationCode": [{
"_": "MYS",
"listID": "3166-1",
"listAgencyID": "ISO"
}
]
}
]
}
],
"PartyLegalEntity": [{
"RegistrationName": [{
"_": "BuyerName"
}
]
}
],
"Contact": [{
"Telephone": [{
"_": "123456789012"
}
],
"ElectronicMail": [{
"_": "Buyer@gmail.com"
}
]
}
]
}
]
}
],
"Delivery": [{
"DeliveryParty": [{
"PartyLegalEntity": [{
"RegistrationName": [{
"_": ""
}
]
}
],
"PostalAddress": [{
"CityName": [{
"_": ""
}
],
"PostalZone": [{
"_": ""
}
],
"CountrySubentityCode": [{
"_": ""
}
],
"AddressLine": [{
"Line": [{
"_": ""
}
]
}, {
"Line": [{
"_": ""
}
]
}, {
"Line": [{
"_": ""
}
]
}
],
"Country": [{
"IdentificationCode": [{
"_": "",
"listID": "",
"listAgencyID": ""
}
]
}
]
}
],
"PartyIdentification": [{
"ID": [{
"_": "",
"schemeID": ""
}
]
}
]
}
],
"Shipment": [{
"ID": [{
"_": ""
}
],
"FreightAllowanceCharge": [{
"ChargeIndicator": [{
"_": true
}
],
"AllowanceChargeReason": [{
"_": ""
}
],
"Amount": [{
"_": 0,
"currencyID": "MYR"
}
]
}
]
}
]
}
],
"PaymentMeans": [{
"PaymentMeansCode": [{
"_": ""
}
],
"PayeeFinancialAccount": [{
"ID": [{
"_": ""
}
]
}
]
}
],
"PaymentTerms": [{
"Note": [{
"_": ""
}
]
}
],
"PrepaidPayment": [{
"ID": [{
"_": ""
}
],
"PaidAmount": [{
"_": 0,
"currencyID": "MYR"
}
],
"PaidDate": [{
"_": ""
}
],
"PaidTime": [{
"_": ""
}
]
}
],
"AllowanceCharge": [{
"ChargeIndicator": [{
"_": true
}
],
"AllowanceChargeReason": [{
"_": ""
}
],
"Amount": [{
"_": 0,
"currencyID": "MYR"
}
]
}, {
"ChargeIndicator": [{
"_": false
}
],
"AllowanceChargeReason": [{
"_": ""
}
],
"Amount": [{
"_": 0,
"currencyID": "MYR"
}
]
}
],
"TaxTotal": [{
"TaxAmount": [{
"_": 15680,
"currencyID": "MYR"
}
],
"TaxSubtotal": [{
"TaxableAmount": [{
"_": 784000,
"currencyID": "MYR"
}
],
"TaxAmount": [{
"_": 15680,
"currencyID": "MYR"
}
],
"TaxCategory": [{
"ID": [{
"_": "02"
}
],
"TaxScheme": [{
"ID": [{
"_": "OTH",
"schemeAgencyID": "6",
"schemeID": "UN/ECE 5153"
}
]
}
]
}
]
}
]
}
],
"LegalMonetaryTotal": [{
"LineExtensionAmount": [{
"_": 784000,
"currencyID": "MYR"
}
],
"TaxExclusiveAmount": [{
"_": 784000,
"currencyID": "MYR"
}
],
"TaxInclusiveAmount": [{
"_": 799680,
"currencyID": "MYR"
}
],
"AllowanceTotalAmount": [{
"_": 0,
"currencyID": "MYR"
}
],
"ChargeTotalAmount": [{
"_": 0,
"currencyID": "MYR"
}
],
"PayableAmount": [{
"_": 799680,
"currencyID": "MYR"
}
],
"PayableRoundingAmount": [{
"_": 0,
"currencyID": "MYR"
}
]
}
],
"InvoiceLine": [{
"AllowanceCharge": [{
"Amount": [{
"_": 16000,
"currencyID": "MYR"
}
],
"ChargeIndicator": [{
"_": false
}
],
"MultiplierFactorNumeric": [{
"_": 2
}
],
"AllowanceChargeReason": [{
"_": "Reason"
}
]
}
],
"ID": [{
"_": "1"
}
],
"InvoicedQuantity": [{
"_": 80,
"unitCode": "KAT"
}
],
"Item": [{
"CommodityClassification": [{
"ItemClassificationCode": [{
"_": "001",
"listID": "CLASS"
}
]
}, {
"ItemClassificationCode": [{
"_": "002",
"listID": "CLASS"
}
]
}, {
"ItemClassificationCode": [{
"_": "003",
"listID": "CLASS"
}
]
}
],
"Description": [{
"_": "Product"
}
],
"OriginCountry": [{
"IdentificationCode": [{
"_": ""
}
]
}
]
}
],
"ItemPriceExtension": [{
"Amount": [{
"_": 800000,
"currencyID": "MYR"
}
]
}
],
"LineExtensionAmount": [{
"_": 784000,
"currencyID": "MYR"
}
],
"Price": [{
"PriceAmount": [{
"_": 10000,
"currencyID": "MYR"
}
]
}
],
"TaxTotal": [{
"TaxAmount": [{
"_": 15680,
"currencyID": "MYR"
}
],
"TaxSubtotal": [{
"TaxableAmount": [{
"_": 784000,
"currencyID": "MYR"
}
],
"TaxAmount": [{
"_": 15680,
"currencyID": "MYR"
}
],
"Percent": [{
"_": 2
}
],
"TaxCategory": [{
"ID": [{
"_": "02"
}
],
"TaxScheme": [{
"ID": [{
"_": "OTH",
"schemeAgencyID": "6",
"schemeID": "UN/ECE 5153"
}
]
}
]
}
]
}
]
}
]
}
],
"TaxExchangeRate": [{
"SourceCurrencyCode": [{
"_": "MYR"
}
],
"TargetCurrencyCode": [{
"_": "MYR"
}
],
"CalculationRate": [{
"_": 0
}
]
}
],
}
]
}
Step 1: Transform the document
The document will be required to be transformed by performing the following:
• Removing the sections “UBLExtensions”, and “Signature” if they do exist.
• Minify the file by removing new lines and not needed spaces.
The output of this step would be a transformed document. The input document shown above once transformed it should be as per the below JSON file.
{"_D":"urn:oasis:names:specification:ubl:schema:xsd:Invoice-2","_A":"urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2","_B":"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2","Invoice":[{"ID":[{"_":"705725225958"}],"IssueDate":[{"_":"2024-06-27"}],"IssueTime":[{"_":"13:22:00Z"}],"InvoiceTypeCode":[{"_":"01","listVersionID":"1.1"}],"DocumentCurrencyCode":[{"_":"MYR"}],"InvoicePeriod":[{"StartDate":[{"_":""}],"EndDate":[{"_":""}],"Description":[{"_":""}]}],"BillingReference":[{"AdditionalDocumentReference":[{"ID":[{"_":"1234"}]}]}],"AdditionalDocumentReference":[{"ID":[{"_":"762673792005"}]}],"AccountingSupplierParty":[{"AdditionalAccountID":[{"_":"","schemeAgencyName":"CertEx"}],"Party":[{"IndustryClassificationCode":[{"_":"61902","name":"Provision of telecommunications services over existing telecom connection"}],"PartyIdentification":[{"ID":[{"_":"C1234567890","schemeID":"TIN"}]},{"ID":[{"_":"1234567890","schemeID":"BRN"}]},{"ID":[{"_":"02332234234343","schemeID":"SST"}]},{"ID":[{"_":"03434234342343432","schemeID":"TTX"}]}],"PostalAddress":[{"CityName":[{"_":"ASAJAYA"}],"PostalZone":[{"_":"94600"}],"CountrySubentityCode":[{"_":"01"}],"AddressLine":[{"Line":[{"_":"Line 1"}]},{"Line":[{"_":"Line 2"}]},{"Line":[{"_":"Line 3"}]}],"Country":[{"IdentificationCode":[{"_":"MYS","listID":"3166-1","listAgencyID":"ISO"}]}]}],"PartyLegalEntity":[{"RegistrationName":[{"_":"KXXX_XXXXDN BHD"}]}],"Contact":[{"Telephone":[{"_":"0326162888"}],"ElectronicMail":[{"_":"noreply@email.com"}]}]}]}],"AccountingCustomerParty":[{"Party":[{"PartyIdentification":[{"ID":[{"_":"C1234567890","schemeID":"TIN"}]},{"ID":[{"_":"1234567890","schemeID":"BRN"}]}],"PostalAddress":[{"CityName":[{"_":"SEMUA NEGERI"}],"PostalZone":[{"_":"81500"}],"CountrySubentityCode":[{"_":"00"}],"AddressLine":[{"Line":[{"_":"buyerAddressLine1"}]},{"Line":[{"_":"buyerAddressLine2"}]},{"Line":[{"_":""}]}],"Country":[{"IdentificationCode":[{"_":"MYS","listID":"3166-1","listAgencyID":"ISO"}]}]}],"PartyLegalEntity":[{"RegistrationName":[{"_":"BuyerName"}]}],"Contact":[{"Telephone":[{"_":"123456789012"}],"ElectronicMail":[{"_":"Buyer@gmail.com"}]}]}]}],"Delivery":[{"DeliveryParty":[{"PartyLegalEntity":[{"RegistrationName":[{"_":""}]}],"PostalAddress":[{"CityName":[{"_":""}],"PostalZone":[{"_":""}],"CountrySubentityCode":[{"_":""}],"AddressLine":[{"Line":[{"_":""}]},{"Line":[{"_":""}]},{"Line":[{"_":""}]}],"Country":[{"IdentificationCode":[{"_":"","listID":"","listAgencyID":""}]}]}],"PartyIdentification":[{"ID":[{"_":"","schemeID":""}]}]}],"Shipment":[{"ID":[{"_":""}],"FreightAllowanceCharge":[{"ChargeIndicator":[{"_":true}],"AllowanceChargeReason":[{"_":""}],"Amount":[{"_":0,"currencyID":"MYR"}]}]}]}],"PaymentMeans":[{"PaymentMeansCode":[{"_":""}],"PayeeFinancialAccount":[{"ID":[{"_":""}]}]}],"PaymentTerms":[{"Note":[{"_":""}]}],"PrepaidPayment":[{"ID":[{"_":""}],"PaidAmount":[{"_":0,"currencyID":"MYR"}],"PaidDate":[{"_":""}],"PaidTime":[{"_":""}]}],"AllowanceCharge":[{"ChargeIndicator":[{"_":true}],"AllowanceChargeReason":[{"_":""}],"Amount":[{"_":0,"currencyID":"MYR"}]},{"ChargeIndicator":[{"_":false}],"AllowanceChargeReason":[{"_":""}],"Amount":[{"_":0,"currencyID":"MYR"}]}],"TaxTotal":[{"TaxAmount":[{"_":15680,"currencyID":"MYR"}],"TaxSubtotal":[{"TaxableAmount":[{"_":784000,"currencyID":"MYR"}],"TaxAmount":[{"_":15680,"currencyID":"MYR"}],"TaxCategory":[{"ID":[{"_":"02"}],"TaxScheme":[{"ID":[{"_":"OTH","schemeAgencyID":"6","schemeID":"UN/ECE 5153"}]}]}]}]}],"LegalMonetaryTotal":[{"LineExtensionAmount":[{"_":784000,"currencyID":"MYR"}],"TaxExclusiveAmount":[{"_":784000,"currencyID":"MYR"}],"TaxInclusiveAmount":[{"_":799680,"currencyID":"MYR"}],"AllowanceTotalAmount":[{"_":0,"currencyID":"MYR"}],"ChargeTotalAmount":[{"_":0,"currencyID":"MYR"}],"PayableAmount":[{"_":799680,"currencyID":"MYR"}],"PayableRoundingAmount":[{"_":0,"currencyID":"MYR"}]}],"InvoiceLine":[{"AllowanceCharge":[{"Amount":[{"_":16000,"currencyID":"MYR"}],"ChargeIndicator":[{"_":false}],"MultiplierFactorNumeric":[{"_":2}],"AllowanceChargeReason":[{"_":"Reason"}]}],"ID":[{"_":"1"}],"InvoicedQuantity":[{"_":80,"unitCode":"KAT"}],"Item":[{"CommodityClassification":[{"ItemClassificationCode":[{"_":"001","listID":"CLASS"}]},{"ItemClassificationCode":[{"_":"002","listID":"CLASS"}]},{"ItemClassificationCode":[{"_":"003","listID":"CLASS"}]}],"Description":[{"_":"Product"}],"OriginCountry":[{"IdentificationCode":[{"_":""}]}]}],"ItemPriceExtension":[{"Amount":[{"_":800000,"currencyID":"MYR"}]}],"LineExtensionAmount":[{"_":784000,"currencyID":"MYR"}],"Price":[{"PriceAmount":[{"_":10000,"currencyID":"MYR"}]}],"TaxTotal":[{"TaxAmount":[{"_":15680,"currencyID":"MYR"}],"TaxSubtotal":[{"TaxableAmount":[{"_":784000,"currencyID":"MYR"}],"TaxAmount":[{"_":15680,"currencyID":"MYR"}],"Percent":[{"_":2}],"TaxCategory":[{"ID":[{"_":"02"}],"TaxScheme":[{"ID":[{"_":"OTH","schemeAgencyID":"6","schemeID":"UN/ECE 5153"}]}]}]}]}]}],"TaxExchangeRate":[{"SourceCurrencyCode":[{"_":"MYR"}],"TargetCurrencyCode":[{"_":"MYR"}],"CalculationRate":[{"_":0}]}],}]}
Step 2: Calculate the document digest
The next step is to calculate the document digest to be signed using the certificate. The document digest is calculated using the following steps.
// assume document is loaded in the variable document
using (SHA256 sha256 = SHA256.Create())
{
var hash = sha256.ComputeHash(System.Text.Encoding.UTF8.GetBytes(document));
var docdigest = Convert.ToBase64String(hash);
}
Step 3: Sign the document digest using the certificate
The next step is to sign the property docdigest that is calculated in the previous step. This should be performed by loading the certificate to be used to sign the document as per the certificate generation guidance. Then use this certificate to sign the document digest value.
The following is example pseudo code that shows how this can be performed.
X509Certificate2 cert = new X509Certificate2();
// Load the certificate from the file store or the key store as required
RSACryptoServiceProvider privateKeyProvider = (RSACryptoServiceProvider)cert.PrivateKey;
var sign = privateKeyProvider.SignHash(hash, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
var signature = Convert.ToBase64String(sign);
Step 4: Calculate the certificate digest
The next step is to calculate the certificate digest value. The following is example pseudo code that shows how this can be performed.
X509Certificate cert = new X509Certificate();
// Load the certificate from the file store or the key store as required
var certash = cert.GetCertHash(System.Security.Cryptography.HashAlgorithmName.SHA256);
var certdigest = Convert.ToBase64String(certash);
Step 5: Populate the signed properties section
The next step is to populate the signed properties section using the values that are already calculated previously. A sample of the output for the signed properties section for the input sample document as per below.
"SignedProperties": [{
"Id": "id-xades-signed-props",
"SignedSignatureProperties": [{
"SigningTime": [{
"_": "2024-07-27T13:22:39Z"
}
],
"SigningCertificate": [{
"Cert": [{
"CertDigest": [{
"DigestMethod": [{
"_": "",
"Algorithm": "http://www.w3.org/2001/04/xmlenc#sha256"
}
],
"DigestValue": [{
"_": "tj0XtM/FsDzmOcHabTxkKcnH54KkZjkB72ah/utcaqA="
}
]
}
],
"IssuerSerial": [{
"X509IssuerName": [{
"_": "CN=Trial LHDNM Sub CA V1, OU=Terms of use at http://www.posdigicert.com.my, O=LHDNM, C=MY"
}
],
"X509SerialNumber": [{
"_": "114094489988964920302056692430494377791"
}
]
}
]
}
]
}
]
}
]
}
]
Step 6: Calculate the signed properties section digest
The signed properties section that is prepared in the previous is then used to calculate the digest. This has to be performed by taking the outer content of the signed properties section and minify the section. The following is an example of the signed properties section that would be then used to calculate the signed properties section digest from the sample already provided above.
{"Target":"signature","SignedProperties":[{"Id":"id-xades-signed-props","SignedSignatureProperties":[{"SigningTime":[{"_":"2024-07-27T13:22:39Z"}],"SigningCertificate":[{"Cert":[{"CertDigest":[{"DigestMethod":[{"_":"","Algorithm":"http://www.w3.org/2001/04/xmlenc#sha256"}],"DigestValue":[{"_":"tj0XtM/FsDzmOcHabTxkKcnH54KkZjkB72ah/utcaqA="}]}],"IssuerSerial":[{"X509IssuerName":[{"_":"CN=Trial LHDNM Sub CA V1, OU=Terms of use at http://www.posdigicert.com.my, O=LHDNM, C=MY"}],"X509SerialNumber":[{"_":"114094489988964920302056692430494377791"}]}]}]}]}]}]}
Then this content is used to calculate the digest of this content which would be the signed properties section digest value.
The following is example pseudo code that shows how this can be performed.
// assume signedprops is loaded in the variable signedprops
using (SHA256 sha256 = SHA256.Create())
{
var signedpropshash = sha256.ComputeHash(System.Text.Encoding.UTF8.GetBytes(signedprops));
var signedpropsdigest = Convert.ToBase64String(signedpropshash);
}
Step 7: Create the signed JSON document
Using the properties and digests calculated in the previous steps the sections “UBLExtensions”, and “Signature”. The following is an example of the “UBLExtensions” section content given the sample that is provided above.
"UBLExtensions": [{
"UBLExtension": [{
"ExtensionURI": [{
"_": "urn:oasis:names:specification:ubl:dsig:enveloped:xades"
}
],
"ExtensionContent": [{
"UBLDocumentSignatures": [{
"SignatureInformation": [{
"ID": [{
"_": "urn:oasis:names:specification:ubl:signature:1"
}
],
"ReferencedSignatureID": [{
"_": "urn:oasis:names:specification:ubl:signature:Invoice"
}
],
"Signature": [{
"Id": "signature",
"Object": [{
"QualifyingProperties": [{
"Target": "signature",
"SignedProperties": [{
"Id": "id-xades-signed-props",
"SignedSignatureProperties": [{
"SigningTime": [{
"_": "2024-07-27T13:22:39Z"
}
],
"SigningCertificate": [{
"Cert": [{
"CertDigest": [{
"DigestMethod": [{
"_": "",
"Algorithm": "http://www.w3.org/2001/04/xmlenc#sha256"
}
],
"DigestValue": [{
"_": "tj0XtM/FsDzmOcHabTxkKcnH54KkZjkB72ah/utcaqA="
}
]
}
],
"IssuerSerial": [{
"X509IssuerName": [{
"_": "CN=Trial LHDNM Sub CA V1, OU=Terms of use at http://www.posdigicert.com.my, O=LHDNM, C=MY"
}
],
"X509SerialNumber": [{
"_": "114094489988964920302056692430494377791"
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
],
"KeyInfo": [{
"X509Data": [{
"X509Certificate": [{
"_": "MIIFHzCCAwegAwIBAgIQVdXMqnRtSVpwGsGggAonPzANBgkqhkiG9w0BAQsFADB1MQswCQYDVQQGEwJNWTEOMAwGA1UEChMFTEhETk0xNjA0BgNVBAsTLVRlcm1zIG9mIHVzZSBhdCBodHRwOi8vd3d3LnBvc2RpZ2ljZXJ0LmNvbS5teTEeMBwGA1UEAxMVVHJpYWwgTEhETk0gU3ViIENBIFYxMB4XDTIyMDcwMTA4MzQxM1oXDTI0MDcwMTA4MzQxM1owSTELMAkGA1UEBhMCTVkxIzAhBgNVBAMTGk1PSEQgUkVEWlVBTiBCSU4gTU9IRCBUQUlCMRUwEwYDVQQFEww4MTEwMDYxNDYwNDMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCNpRGjwDdMWIwHlKkJS1ZsNwEGIMJeMfwwjtoBzVj2a4D5Xt+P5hMnCvLwqujh3qnid7WeNmZtS509arZxiitWblUeeFGptXDUzt3ulp/ceZQlmJHhGgiKypxzETqSjnLZxZZWmvLlC+ZAWZF8nmt6cWDHXtffnaEWw2YokeANFx4OUJfvp1VsGVMJcVhZDdC3km5iItLGkVQCIZmSwn7dyEnG/zheOlzly4RBAJSaqfWPFHHoaaS5tsCDjAtwOWaop1RzU4fxiN3CoGmqdHOr4N40d8uPQZi4HGGBk6uOhd/wN2x6EgBeaEzan1jAUugnhfrwlT/FuoRYJmfoG55BAgMBAAGjgdY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uerSerial": [{
"X509IssuerName": [{
"_": "CN=Trial LHDNM Sub CA V1, OU=Terms of use at http://www.posdigicert.com.my, O=LHDNM, C=MY"
}
],
"X509SerialNumber": [{
"_": "114094489988964920302056692430494377791"
}
]
}
]
}
]
}
],
"SignatureValue": [{
"_": "Gw5uGjtok0IiPQ+hVH8R2xKFTojrm2fVM8P4wtcfgemqaJSAntAcacb8vcTbU6WAfLcIneEXRHTCG+qzawqBN6bjIl9yfsQ+IGReQhbZqQ43Zh2fFgPBwLo4Ywp4NqiGyGsrd/lm4PPtE8PmZbcQHTudHMYYxDDykA0ok1Lw6Xt/+lR7WHtp8+kHW37V8iPEDWAq5kfHazvke5kkzY+M/mWCzqlE4bIIiEk1lNjovGbER4K8XM3oMQUPpHkYi1P/UUMFP7QIAzMsLXKwmXx1rM77mfmOVrzNHgbetyfPJsfqiDrwQpB6KcODsui5CmhfrphMJs5gwcH7sG+6TNVn6w=="
}
],
"SignedInfo": [{
"SignatureMethod": [{
"_": "",
"Algorithm": "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
}
],
"Reference": [{
"Type": "http://uri.etsi.org/01903/v1.3.2#SignedProperties",
"URI": "#id-xades-signed-props",
"DigestMethod": [{
"_": "",
"Algorithm": "http://www.w3.org/2001/04/xmlenc#sha256"
}
],
"DigestValue": [{
"_": "KEV8ZySPs6wrKyNcwVe7x3sgDwFVRLWWB3yZNSPky1I="
}
]
}, {
"Type": "",
"URI": "",
"DigestMethod": [{
"_": "",
"Algorithm": "http://www.w3.org/2001/04/xmlenc#sha256"
}
],
"DigestValue": [{
"_": "t+vl1+3vDeaganWrHMydIWhg7x/8xFQCa6pkBuLs2w0="
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
]
}
]
The following is an example of the “Signature” section given the sample that is provided above.
"Signature": [
{
"ID": [
{
"_": "urn:oasis:names:specification:ubl:signature:Invoice"
}
],
"SignatureMethod": [
{
"_": "urn:oasis:names:specification:ubl:dsig:enveloped:xades"
}
]
}
]
The final signed document should be already minified including all the content to make sure the document is still valid according to the signature and the signature doesn’t break. The following is a sample of the output signed document including all the sections.
{"_D":"urn:oasis:names:specification:ubl:schema:xsd:Invoice-2","_A":"urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2","_B":"urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2","Invoice":[{"ID":[{"_":"705725225958"}],"IssueDate":[{"_":"2024-06-27"}],"IssueTime":[{"_":"13:22:00Z"}],"InvoiceTypeCode":[{"_":"01","listVersionID":"1.1"}],"DocumentCurrencyCode":[{"_":"MYR"}],"InvoicePeriod":[{"StartDate":[{"_":""}],"EndDate":[{"_":""}],"Description":[{"_":""}]}],"BillingReference":[{"AdditionalDocumentReference":[{"ID":[{"_":"1234"}]}]}],"AdditionalDocumentReference":[{"ID":[{"_":"762673792005"}]}],"AccountingSupplierParty":[{"AdditionalAccountID":[{"_":"","schemeAgencyName":"CertEx"}],"Party":[{"IndustryClassificationCode":[{"_":"61902","name":"Provision of telecommunications services over existing telecom connection"}],"PartyIdentification":[{"ID":[{"_":"C1234567890","schemeID":"TIN"}]},{"ID":[{"_":"1234567890","schemeID":"BRN"}]},{"ID":[{"_":"02332234234343","schemeID":"SST"}]},{"ID":[{"_":"03434234342343432","schemeID":"TTX"}]}],"PostalAddress":[{"CityName":[{"_":"ASAJAYA"}],"PostalZone":[{"_":"94600"}],"CountrySubentityCode":[{"_":"01"}],"AddressLine":[{"Line":[{"_":"Line 1"}]},{"Line":[{"_":"Line 2"}]},{"Line":[{"_":"Line 3"}]}],"Country":[{"IdentificationCode":[{"_":"MYS","listID":"3166-1","listAgencyID":"ISO"}]}]}],"PartyLegalEntity":[{"RegistrationName":[{"_":"KXXX_XXXXDN BHD"}]}],"Contact":[{"Telephone":[{"_":"0326162888"}],"ElectronicMail":[{"_":"noreply@email.com"}]}]}]}],"AccountingCustomerParty":[{"Party":[{"PartyIdentification":[{"ID":[{"_":"C1234567890","schemeID":"TIN"}]},{"ID":[{"_":"1234567890","schemeID":"BRN"}]}],"PostalAddress":[{"CityName":[{"_":"SEMUA NEGERI"}],"PostalZone":[{"_":"81500"}],"CountrySubentityCode":[{"_":"00"}],"AddressLine":[{"Line":[{"_":"buyerAddressLine1"}]},{"Line":[{"_":"buyerAddressLine2"}]},{"Line":[{"_":""}]}],"Country":[{"IdentificationCode":[{"_":"MYS","listID":"3166-1","listAgencyID":"ISO"}]}]}],"PartyLegalEntity":[{"RegistrationName":[{"_":"BuyerName"}]}],"Contact":[{"Telephone":[{"_":"123456789012"}],"ElectronicMail":[{"_":"Buyer@gmail.com"}]}]}]}],"Delivery":[{"DeliveryParty":[{"PartyLegalEntity":[{"RegistrationName":[{"_":""}]}],"PostalAddress":[{"CityName":[{"_":""}],"PostalZone":[{"_":""}],"CountrySubentityCode":[{"_":""}],"AddressLine":[{"Line":[{"_":""}]},{"Line":[{"_":""}]},{"Line":[{"_":""}]}],"Country":[{"IdentificationCode":[{"_":"","listID":"","listAgencyID":""}]}]}],"PartyIdentification":[{"ID":[{"_":"","schemeID":""}]}]}],"Shipment":[{"ID":[{"_":""}],"FreightAllowanceCharge":[{"ChargeIndicator":[{"_":true}],"AllowanceChargeReason":[{"_":""}],"Amount":[{"_":0,"currencyID":"MYR"}]}]}]}],"PaymentMeans":[{"PaymentMeansCode":[{"_":""}],"PayeeFinancialAccount":[{"ID":[{"_":""}]}]}],"PaymentTerms":[{"Note":[{"_":""}]}],"PrepaidPayment":[{"ID":[{"_":""}],"PaidAmount":[{"_":0,"currencyID":"MYR"}],"PaidDate":[{"_":""}],"PaidTime":[{"_":""}]}],"AllowanceCharge":[{"ChargeIndicator":[{"_":true}],"AllowanceChargeReason":[{"_":""}],"Amount":[{"_":0,"currencyID":"MYR"}]},{"ChargeIndicator":[{"_":false}],"AllowanceChargeReason":[{"_":""}],"Amount":[{"_":0,"currencyID":"MYR"}]}],"TaxTotal":[{"TaxAmount":[{"_":15680,"currencyID":"MYR"}],"TaxSubtotal":[{"TaxableAmount":[{"_":784000,"currencyID":"MYR"}],"TaxAmount":[{"_":15680,"currencyID":"MYR"}],"TaxCategory":[{"ID":[{"_":"02"}],"TaxScheme":[{"ID":[{"_":"OTH","schemeAgencyID":"6","schemeID":"UN/ECE 5153"}]}]}]}]}],"LegalMonetaryTotal":[{"LineExtensionAmount":[{"_":784000,"currencyID":"MYR"}],"TaxExclusiveAmount":[{"_":784000,"currencyID":"MYR"}],"TaxInclusiveAmount":[{"_":799680,"currencyID":"MYR"}],"AllowanceTotalAmount":[{"_":0,"currencyID":"MYR"}],"ChargeTotalAmount":[{"_":0,"currencyID":"MYR"}],"PayableAmount":[{"_":799680,"currencyID":"MYR"}],"PayableRoundingAmount":[{"_":0,"currencyID":"MYR"}]}],"InvoiceLine":[{"AllowanceCharge":[{"Amount":[{"_":16000,"currencyID":"MYR"}],"ChargeIndicator":[{"_":false}],"MultiplierFactorNumeric":[{"_":2}],"AllowanceChargeReason":[{"_":"Reason"}]}],"ID":[{"_":"1"}],"InvoicedQuantity":[{"_":80,"unitCode":"KAT"}],"Item":[{"CommodityClassification":[{"ItemClassificationCode":[{"_":"001","listID":"CLASS"}]},{"ItemClassificationCode":[{"_":"002","listID":"CLASS"}]},{"ItemClassificationCode":[{"_":"003","listID":"CLASS"}]}],"Description":[{"_":"Product"}],"OriginCountry":[{"IdentificationCode":[{"_":""}]}]}],"ItemPriceExtension":[{"Amount":[{"_":800000,"currencyID":"MYR"}]}],"LineExtensionAmount":[{"_":784000,"currencyID":"MYR"}],"Price":[{"PriceAmount":[{"_":10000,"currencyID":"MYR"}]}],"TaxTotal":[{"TaxAmount":[{"_":15680,"currencyID":"MYR"}],"TaxSubtotal":[{"TaxableAmount":[{"_":784000,"currencyID":"MYR"}],"TaxAmount":[{"_":15680,"currencyID":"MYR"}],"Percent":[{"_":2}],"TaxCategory":[{"ID":[{"_":"02"}],"TaxScheme":[{"ID":[{"_":"OTH","schemeAgencyID":"6","schemeID":"UN/ECE 5153"}]}]}]}]}]}],"TaxExchangeRate":[{"SourceCurrencyCode":[{"_":"MYR"}],"TargetCurrencyCode":[{"_":"MYR"}],"CalculationRate":[{"_":0}]}],"UBLExtensions":[{"UBLExtension":[{"ExtensionURI":[{"_":"urn:oasis:names:specification:ubl:dsig:enveloped:xades"}],"ExtensionContent":[{"UBLDocumentSignatures":[{"SignatureInformation":[{"ID":[{"_":"urn:oasis:names:specification:ubl:signature:1"}],"ReferencedSignatureID":[{"_":"urn:oasis:names:specification:ubl:signature:Invoice"}],"Signature":[{"Id":"signature","Object":[{"QualifyingProperties":[{"Target":"signature","SignedProperties":[{"Id":"id-xades-signed-props","SignedSignatureProperties":[{"SigningTime":[{"_":"2024-07-27T13:22:39Z"}],"SigningCertificate":[{"Cert":[{"CertDigest":[{"DigestMethod":[{"_":"","Algorithm":"http://www.w3.org/2001/04/xmlenc#sha256"}],"DigestValue":[{"_":"tj0XtM/FsDzmOcHabTxkKcnH54KkZjkB72ah/utcaqA="}]}],"IssuerSerial":[{"X509IssuerName":[{"_":"CN=Trial LHDNM Sub CA V1, OU=Terms of use at http://www.posdigicert.com.my, O=LHDNM, C=MY"}],"X509SerialNumber":[{"_":"114094489988964920302056692430494377791"}]}]}]}]}]}]}]}],"KeyInfo":[{"X509Data":[{"X509Certificate":[{"_":"MIIFHzCCAwegAwIBAgIQVdXMqnRtSVpwGsGggAonPzANBgkqhkiG9w0BAQsFADB1MQswCQYDVQQGEwJNWTEOMAwGA1UEChMFTEhETk0xNjA0BgNVBAsTLVRlcm1zIG9mIHVzZSBhdCBodHRwOi8vd3d3LnBvc2RpZ2ljZXJ0LmNvbS5teTEeMBwGA1UEAxMVVHJpYWwgTEhETk0gU3ViIENBIFYxMB4XDTIyMDcwMTA4MzQxM1oXDTI0MDcwMTA4MzQxM1owSTELMAkGA1UEBhMCTVkxIzAhBgNVBAMTGk1PSEQgUkVEWlVBTiBCSU4gTU9IRCBUQUlCMRUwEwYDVQQFEww4MTEwMDYxNDYwNDMwggEiMA0GCSqGSIb3DQEBAQUA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/DWh2zA8yGNMsR0JQx+74BBDVaulV29h5lHW+IqrwChKzNj27aDE7SYqwHxaETTjp1nV1Zd8t9o8MvpXCWEsH194r06ebpCkMh3IxIR/jn01PRzjz7iaKEegCBpl23BRHXib8DMq5jK/z2CLmvHlJbNRRxd42psp7wVdX48YQhYCNdps/lJmgQxTo7HJFjirxpWdMUP7lxML21YDLCyAXOG0e4g00SqA8SJg3ROSzZXKZP0nvezSryXWmr8STTTGia+YjjynHoK8o0/uYgCW2SC+ZfhPH9gHJv9ZeNQ=="}],"X509SubjectName":[{"_":"SERIALNUMBER=811006146043, CN=MOHD REDZUAN BIN MOHD TAIB, C=MY"}],"X509IssuerSerial":[{"X509IssuerName":[{"_":"CN=Trial LHDNM Sub CA V1, OU=Terms of use at http://www.posdigicert.com.my, O=LHDNM, C=MY"}],"X509SerialNumber":[{"_":"114094489988964920302056692430494377791"}]}]}]}],"SignatureValue":[{"_":"Gw5uGjtok0IiPQ+hVH8R2xKFTojrm2fVM8P4wtcfgemqaJSAntAcacb8vcTbU6WAfLcIneEXRHTCG+qzawqBN6bjIl9yfsQ+IGReQhbZqQ43Zh2fFgPBwLo4Ywp4NqiGyGsrd/lm4PPtE8PmZbcQHTudHMYYxDDykA0ok1Lw6Xt/+lR7WHtp8+kHW37V8iPEDWAq5kfHazvke5kkzY+M/mWCzqlE4bIIiEk1lNjovGbER4K8XM3oMQUPpHkYi1P/UUMFP7QIAzMsLXKwmXx1rM77mfmOVrzNHgbetyfPJsfqiDrwQpB6KcODsui5CmhfrphMJs5gwcH7sG+6TNVn6w=="}],"SignedInfo":[{"SignatureMethod":[{"_":"","Algorithm":"http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"}],"Reference":[{"Type":"http://uri.etsi.org/01903/v1.3.2#SignedProperties","URI":"#id-xades-signed-props","DigestMethod":[{"_":"","Algorithm":"http://www.w3.org/2001/04/xmlenc#sha256"}],"DigestValue":[{"_":"KEV8ZySPs6wrKyNcwVe7x3sgDwFVRLWWB3yZNSPky1I="}]},{"Type":"","URI":"","DigestMethod":[{"_":"","Algorithm":"http://www.w3.org/2001/04/xmlenc#sha256"}],"DigestValue":[{"_":"t+vl1+3vDeaganWrHMydIWhg7x/8xFQCa6pkBuLs2w0="}]}]}]}]}]}]}]}]}],"Signature":[{"ID":[{"_":"urn:oasis:names:specification:ubl:signature:Invoice"}],"SignatureMethod":[{"_":"urn:oasis:names:specification:ubl:dsig:enveloped:xades"}]}]}]}