He invoice hash API body does not match the (calculated) Hash of the XML

{“validationResults”: {
“infoMessages”: [
{
“type”: “INFO”,
“code”: “XSD_ZATCA_VALID”,
“category”: “XSD validation”,
“message”: “Complied with UBL 2.1 standards in line with ZATCA specifications”,
“status”: “PASS”
}
],
“warningMessages”: ,
“errorMessages”: [
{
“type”: “ERROR”,
“code”: “invalid-invoice-hash”,
“category”: “INVOICE_HASHING_ERRORS”,
“message”: “The invoice hash API body does not match the (calculated) Hash of the XML”,
“status”: “ERROR”
}
],
“status”: “ERROR”
},
“reportingStatus”: null,
“clearanceStatus”: “NOT_CLEARED”,
“qrSellertStatus”: null,
“qrBuyertStatus”: null
}

i used .NET SDK

i signed invoice by
SignResult signedResult = _eInvoiceSigner.SignDocument(eInvoice, cer, privateKey);

Salam Mohammad,
As the error is not cleared means you are trying B2B invoices and if so then why you are signing it using SDK? B2B you don’t need to sign locally and generate QR code but ZATCA will do once your will send for clearance and will send back signed xml. Please elaborate. thanks

1 Like

thanks : but the error when compliance invoice by using link : https://gw-fatoora.zatca.gov.sa/e-invoicing/simulation/compliance/invoices

Hi,
Please share your full XML and also how you calculated hash of invoice seems it is wrong calculated or you have special characters in your xml and when sent to ZATCA those are getting removed hence hash will not match with your hash sent in json. thanks

my invoice

<?xml version="1.0" encoding="UTF-8"?>

ext:UBLExtensions
ext:UBLExtension
ext:ExtensionURIurn: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:IDurn:oasis:names:specification:ubl:signature:1</cbc:ID>
sbc:ReferencedSignatureIDurn:oasis:names:specification:ubl:signature:Invoice</sbc:ReferencedSignatureID>
<ds:Signature xmlns:ds=“XML-Signature Syntax and Processing” Id=“signature”>
ds:SignedInfo
<ds:CanonicalizationMethod Algorithm=“Canonical XML 1.1”/>
<ds:SignatureMethod Algorithm=“xmldsig-more namespace”/>
<ds:Reference Id=“invoiceSignedData” URI=“”>
ds:Transforms
<ds:Transform Algorithm=“XML Path Language (XPath)”>
ds:XPathnot(//ancestor-or-self::ext:UBLExtensions)</ds:XPath>
</ds:Transform>
<ds:Transform Algorithm=“XML Path Language (XPath)”>
ds:XPathnot(//ancestor-or-self::cac:Signature)</ds:XPath>
</ds:Transform>
<ds:Transform Algorithm=“XML Path Language (XPath)”>
ds:XPathnot(//ancestor-or-self::cac:AdditionalDocumentReference[cbc:ID=‘QR’])</ds:XPath>
</ds:Transform>
<ds:Transform Algorithm=“Canonical XML 1.1”/>
</ds:Transforms>
<ds:DigestMethod Algorithm=“XML Encryption Syntax and Processing”/>
ds:DigestValuef+0WCqnPkInI+eL9G3LAry12fTPf+toC9UX07F4fI+s=</ds:DigestValue>
</ds:Reference>
<ds:Reference Type=“XML-Signature Syntax and Processing” URI=“#xadesSignedProperties”>
<ds:DigestMethod Algorithm=“XML Encryption Syntax and Processing”/>
ds:DigestValueODQwNTg1NTBhMjMzM2YxY2ZkZjVkYzdlNTZiZjY0ODJjMjNkYWI4MTUzNjdmNDVjMjAwZTBjODc2YTNhMWQ1Ng==</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
ds:SignatureValueMEUCIBxyR8rc4K8728wdSF4XSDqPs+rIL+3TFh9m+aNxQPtSAiEA6cHapItvp13yMSu66NbOg2CpomHwUSnYJ9h6uGQ65aY=</ds:SignatureValue>
ds:KeyInfo
ds:X509Data
ds:X509CertificateMIID3jCCA4SgAwIBAgITEQAAOAPF90Ajs/xcXwABAAA4AzAKBggqhkjOPQQDAjBiMRUwEwYKCZImiZPyLGQBGRYFbG9jYWwxEzARBgoJkiaJk/IsZAEZFgNnb3YxFzAVBgoJkiaJk/IsZAEZFgdleHRnYXp0MRswGQYDVQQDExJQUl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j0EAwIDSAAwRQIhALE/ichmnWXCUKUbca3yci8oqwaLvFdHVjQrveI9uqAbAiA9hC4M8jgMBADPSzmd2uiPJA6gKR3LE03U75eqbC/rXA==</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
ds:Object
<xades:QualifyingProperties xmlns:xades=“Assigned ETSI XML URIs” Target=“signature”>
<xades:SignedProperties Id=“xadesSignedProperties”>
xades:SignedSignatureProperties
xades:SigningTime2024-01-14T10:21:40</xades:SigningTime>
xades:SigningCertificate
xades:Cert
xades:CertDigest
<ds:DigestMethod Algorithm=“XML Encryption Syntax and Processing”/>
ds:DigestValueZDMwMmI0MTE1NzVjOTU2NTk4YzVlODhhYmI0ODU2NDUyNTU2YTVhYjhhMDFmN2FjYjk1YTA2OWQ0NjY2MjQ4NQ==</ds:DigestValue>
</xades:CertDigest>
xades:IssuerSerial
ds:X509IssuerNameCN=PRZEINVOICESCA4-CA, DC=extgazt, DC=gov, DC=local</ds:X509IssuerName>
ds:X509SerialNumber379112742831380471835263969587287663520528387</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>

<cbc:ProfileID>reporting:1.0</cbc:ProfileID>
<cbc:ID>SME00023</cbc:ID>
<cbc:UUID>8d487816-70b8-4ade-a618-9d620b73814a</cbc:UUID>
<cbc:IssueDate>2022-09-07</cbc:IssueDate>
<cbc:IssueTime>12:21:28</cbc:IssueTime>
<cbc:InvoiceTypeCode name="0100000">388</cbc:InvoiceTypeCode>
<cbc:DocumentCurrencyCode>SAR</cbc:DocumentCurrencyCode>
<cbc:TaxCurrencyCode>SAR</cbc:TaxCurrencyCode>
<cac:AdditionalDocumentReference>
    <cbc:ID>ICV</cbc:ID>
    <cbc:UUID>23</cbc:UUID>
</cac:AdditionalDocumentReference>
<cac:AdditionalDocumentReference>
    <cbc:ID>PIH</cbc:ID>
    <cac:Attachment>
        <cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain">NWZlY2ViNjZmZmM4NmYzOGQ5NTI3ODZjNmQ2OTZjNzljMmRiYzIzOWRkNGU5MWI0NjcyOWQ3M2EyN2ZiNTdlOQ==</cbc:EmbeddedDocumentBinaryObject>
    </cac:Attachment>
</cac:AdditionalDocumentReference>


<cac:AdditionalDocumentReference>
    <cbc:ID>QR</cbc:ID>
    <cac:Attachment>
        <cbc:EmbeddedDocumentBinaryObject mimeCode="text/plain">AW/YtNix2YPYqSDYqtmI2LHZitivINin2YTYqtmD2YbZiNmE2YjYrNmK2Kcg2KjYo9mC2LXZiSDYs9ix2LnYqSDYp9mE2YXYrdiv2YjYr9ipIHwgTWF4aW11bSBTcGVlZCBUZWNoIFN1cHBseSBMVEQCDzM5OTk5OTk5OTkwMDAwMwMTMjAyMi0wOS0wN1QxMjoyMToyOAQENC42MAUDMC42BixmKzBXQ3FuUGtJbkkrZUw5RzNMQXJ5MTJmVFBmK3RvQzlVWDA3RjRmSStzPQdgTUVVQ0lCeHlSOHJjNEs4NzI4d2RTRjRYU0RxUHMrcklMKzNURmg5bSthTnhRUHRTQWlFQTZjSGFwSXR2cDEzeU1TdTY2TmJPZzJDcG9tSHdVU25ZSjloNnVHUTY1YVk9CFgwVjAQBgcqhkjOPQIBBgUrgQQACgNCAAShYIprRJr0UgStM6/S4CQLVUgpfFT2c+nHa+V/jKEx6PLxzTZcluUOru0/J2jyarRqE4yY2jyDCeLte3UpP1R4</cbc:EmbeddedDocumentBinaryObject>
    </cac:Attachment>

</cac:AdditionalDocumentReference>cac:Signature
cbc:IDurn:oasis:names:specification:ubl:signature:Invoice</cbc:ID>
cbc:SignatureMethodurn:oasis:names:specification:ubl:dsig:enveloped:xades</cbc:SignatureMethod>
</cac:Signature>cac:AccountingSupplierParty
cac:Party
cac:PartyIdentification
<cbc:ID schemeID=“CRN”>1010010000</cbc:ID>
</cac:PartyIdentification>
cac:PostalAddress
cbc:StreetNamejazan</cbc:StreetName>
cbc:BuildingNumber2322</cbc:BuildingNumber>
cbc:CitySubdivisionNameAl-Murabba</cbc:CitySubdivisionName>
cbc:CityNameRiyadh</cbc:CityName>
cbc:PostalZone23333</cbc:PostalZone>
cac:Country
cbc:IdentificationCodeSA</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
cac:PartyTaxScheme
cbc:CompanyID302125376400003</cbc:CompanyID>
cac:TaxScheme
cbc:IDVAT</cbc:ID>
</cac:TaxScheme>
</cac:PartyTaxScheme>
cac:PartyLegalEntity
cbc:RegistrationNameFatoora Samples LTD</cbc:RegistrationName>
</cac:PartyLegalEntity>
</cac:Party>
</cac:AccountingSupplierParty>
cac:AccountingCustomerParty
cac:Party
cac:PostalAddress
cbc:StreetNameSalah Al-Din</cbc:StreetName>
cbc:BuildingNumber1111</cbc:BuildingNumber>
cbc:CitySubdivisionNameAl-Murooj</cbc:CitySubdivisionName>
cbc:CityNameRiyadh</cbc:CityName>
cbc:PostalZone12222</cbc:PostalZone>
cac:Country
cbc:IdentificationCodeSA</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
cac:PartyTaxScheme
cbc:CompanyID311344436300003</cbc:CompanyID>
cac:TaxScheme
cbc:IDVAT</cbc:ID>
</cac:TaxScheme>
</cac:PartyTaxScheme>
cac:PartyLegalEntity
cbc:RegistrationNameMaximum Speed Tech Supply LTD</cbc:RegistrationName>
</cac:PartyLegalEntity>
</cac:Party>
</cac:AccountingCustomerParty>
cac:Delivery
cbc:ActualDeliveryDate2022-09-07</cbc:ActualDeliveryDate>
</cac:Delivery>
cac:PaymentMeans
cbc:PaymentMeansCode10</cbc:PaymentMeansCode>
</cac:PaymentMeans>
cac:AllowanceCharge
cbc:ChargeIndicatorfalse</cbc:ChargeIndicator>
cbc:AllowanceChargeReasondiscount</cbc:AllowanceChargeReason>
<cbc:Amount currencyID=“SAR”>0.00</cbc:Amount>
cac:TaxCategory
<cbc:ID schemeID=“UN/ECE 5305” schemeAgencyID=“6”>S</cbc:ID>
cbc:Percent15</cbc:Percent>
cac:TaxScheme
<cbc:ID schemeID=“UN/ECE 5153” schemeAgencyID=“6”>VAT</cbc:ID>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:AllowanceCharge>
cac:TaxTotal
<cbc:TaxAmount currencyID=“SAR”>0.6</cbc:TaxAmount>
</cac:TaxTotal>
cac:TaxTotal
<cbc:TaxAmount currencyID=“SAR”>0.6</cbc:TaxAmount>
cac:TaxSubtotal
<cbc:TaxableAmount currencyID=“SAR”>4.00</cbc:TaxableAmount>
<cbc:TaxAmount currencyID=“SAR”>0.60</cbc:TaxAmount>
cac:TaxCategory
<cbc:ID schemeID=“UN/ECE 5305” schemeAgencyID=“6”>S</cbc:ID>
cbc:Percent15.00</cbc:Percent>
cac:TaxScheme
<cbc:ID schemeID=“UN/ECE 5153” schemeAgencyID=“6”>VAT</cbc:ID>
</cac:TaxScheme>
</cac:TaxCategory>
</cac:TaxSubtotal>
</cac:TaxTotal>
cac:LegalMonetaryTotal
<cbc:LineExtensionAmount currencyID=“SAR”>4.00</cbc:LineExtensionAmount>
<cbc:TaxExclusiveAmount currencyID=“SAR”>4.00</cbc:TaxExclusiveAmount>
<cbc:TaxInclusiveAmount currencyID=“SAR”>4.60</cbc:TaxInclusiveAmount>
<cbc:AllowanceTotalAmount currencyID=“SAR”>0.00</cbc:AllowanceTotalAmount>
<cbc:PrepaidAmount currencyID=“SAR”>0.00</cbc:PrepaidAmount>
<cbc:PayableAmount currencyID=“SAR”>4.60</cbc:PayableAmount>
</cac:LegalMonetaryTotal>
cac:InvoiceLine
cbc:ID1</cbc:ID>
<cbc:InvoicedQuantity unitCode=“PCE”>2.000000</cbc:InvoicedQuantity>
<cbc:LineExtensionAmount currencyID=“SAR”>4.00</cbc:LineExtensionAmount>
cac:TaxTotal
<cbc:TaxAmount currencyID=“SAR”>0.60</cbc:TaxAmount>
<cbc:RoundingAmount currencyID=“SAR”>4.60</cbc:RoundingAmount>
</cac:TaxTotal>
cac:Item
cbc:Namepencel</cbc:Name>
cac:ClassifiedTaxCategory
cbc:IDS</cbc:ID>
cbc:Percent15.00</cbc:Percent>
cac:TaxScheme
cbc:IDVAT</cbc:ID>
</cac:TaxScheme>
</cac:ClassifiedTaxCategory>
</cac:Item>
cac:Price
<cbc:PriceAmount currencyID=“SAR”>2.00</cbc:PriceAmount>
cac:AllowanceCharge
cbc:ChargeIndicatortrue</cbc:ChargeIndicator>
cbc:AllowanceChargeReasondiscount</cbc:AllowanceChargeReason>
<cbc:Amount currencyID=“SAR”>0.00</cbc:Amount>
</cac:AllowanceCharge>
</cac:Price>
</cac:InvoiceLine>

this is my code :

     var hashInvoice = _eInvoiceHashGenerator.GenerateEInvoiceHashing(eInvoice);

        var cer = Base64Converter.Base64Decode(binarySecurityToken);

        SignResult signedResult = _eInvoiceSigner.SignDocument(eInvoice, cer, privateKey);

hi>>thank you >> ok i will send now

Hi,
As you have B2B then remove ext:UBLExtensions to </ext:UBLExtensions> secondly upload as text document it is not a proper xml.

thank you>

i removed ext:UBLExtensions to </ext:UBLExtensions> and uploaded it as text but i still have same error

{
“validationResults”: {
“infoMessages”: [
{
“type”: “INFO”,
“code”: “XSD_ZATCA_VALID”,
“category”: “XSD validation”,
“message”: “Complied with UBL 2.1 standards in line with ZATCA specifications”,
“status”: “PASS”
}
],
“warningMessages”: ,
“errorMessages”: [
{
“type”: “ERROR”,
“code”: “invalid-invoice-hash”,
“category”: “INVOICE_HASHING_ERRORS”,
“message”: “The invoice hash API body does not match the (calculated) Hash of the XML”,
“status”: “ERROR”
}
],
“status”: “ERROR”
},
“reportingStatus”: null,
“clearanceStatus”: “NOT_CLEARED”,
“qrSellertStatus”: null,
“qrBuyertStatus”: null
}

notic : i am use .NET SDK to sign invice and when i use cmd :fatoora -sign -qr -invoice Standard_Invoice.xml -signedinvoice signed.xml it’s work well

Dear @mohmed58264 ,
How you solve this problem?

If you still didn’t fix this problem send me your contact by mail
Eng.Osama@topex-solutions.com

@Madleen Did you fix this problem ?