INVALID-INVOICE-HASH 🔐 Cryptography, Hash & Security error

INVALID-INVOICE-HASH: Cryptographic Invoice Hash Mismatch

خطأ هاش الفاتورة غير صالح: عدم تطابق بصمة الفاتورة الرقمية

Official ZATCA Specification:

ZATCA clearance/reporting engine validates the SHA-256 digest of the canonicalized UBL 2.1 invoice XML. If characters, whitespace, or transforms deviate, hash validation fails.

XPath Context: /ubl:Invoice/ext:UBLExtensions/.../ds:DigestValue

📌 Overview & Impact

The generated SHA-256 digest of the canonicalized invoice does not match the hash verified by ZATCA validator.

الوصف بالعربية: بصمة SHA-256 المحتسبة لملف XML لا تطابق البصمة المستخرجة بواسطة مدقق زاتكا نتيجة أخطاء في التحويل المعياري C14N.

⚠️ Common Causes for Rejection

  • Failing to exclude <ext:UBLExtensions>, QR DocumentReference, and <cac:Signature> nodes before canonicalization
  • Using non-C14N11 canonicalization (e.g. basic XML string serialization)
  • Operating system line-ending differences (CRLF \r\n vs LF \n)
  • Modifying any invoice field after computing the hash

How to Fix & Resolve

1

Follow ZATCA Transform Steps Exactly

1. Remove UBLExtensions. 2. Remove QR AdditionalDocumentReference. 3. Remove Signature. 4. Canonicalize XML with C14N11. 5. Hash binary with SHA-256. 6. Base64 encode.

2

Enforce UTF-8 & LF Line Endings

Ensure all XML processing operates strictly in UTF-8 encoding with standard Unix LF (\n) line breaks.

💻 Code Comparison: Invalid vs Compliant UBL 2.1 XML

❌ Invalid XML (Rejected by ZATCA) Invalid Payload
// Anti-pattern: Hashing the full XML directly without transforms
const hash = crypto.createHash('sha256').update(fullXmlString).digest('base64');
✓ Valid XML (Compliant UBL 2.1) Valid Payload
// Best practice: Transform, canonicalize, then hash
const cleanedXml = stripSignatureNodes(rawXml);
const canonicalXml = c14n11Canonicalize(cleanedXml);
const invoiceHash = crypto.createHash('sha256').update(canonicalXml, 'utf8').digest('base64');

Verify Your Invoice XML Online

Use Qeemah's free developer tools to inspect transforms, C14N digests, and Phase 2 QR codes.

Frequently Asked Questions

Can I test my invoice hash before sending to production?

Yes! Use Qeemah's free ZATCA XML Viewer & Hash Validator tool to verify your XML transforms, canonicalization, and SHA-256 digests instantly.

Stop Fighting Cryptic ZATCA XML Errors

Qeemah handles Phase 2 e-invoicing, cryptographic signing, and real-time clearance automatically. Integrate in minutes.