The invoice hash: how it is computed
A SHA-256 fingerprint of the document after removing the stamp and QR blocks and canonicalizing it, written in base64; the stamp and the chain rest on it.
The hash is what actually gets signed: the cryptographic stamp is a signature over the hash, not the file. It is also what the next document carries as the previous invoice hash, what is sent to FATOORA with every request, and what appears in QR tag 6.
Before hashing, three blocks are removed because they are not ready yet or contain the hash itself: UBLExtensions (the stamp), the QR reference and cac:Signature. The XML declaration is dropped, the text is canonicalized with C14N 1.1, SHA-256 is computed and the 32 bytes are base64-encoded.
Because the hash is taken over the document text, a difference in a space, attribute order or character encoding gives a different hash. That is why the text is canonicalized first, and why ZATCA's stamp does not change the hash of a cleared invoice: the stamp sits in excluded blocks.
In JooDax
BuiltThe programs use no C14N engine: they write the document already in canonical form (decision D-01: escape &, < and > only, leave quotes), then cut the three blocks from the text, drop the declaration and compute SHA-256. The hash is taken from a draft of the final document with placeholders in the excluded blocks; ZATCA's validator accepted the result, and 400 golden cases hold it to version 1.0.
crates/jdx-einvoice-sa/src/xml.rs
Steps
- Remove the ext:UBLExtensions block.
- Remove the AdditionalDocumentReference whose ID is QR.
- Remove cac:Signature.
- Drop the XML declaration and canonicalize with C14N 1.1.
- Compute SHA-256 and base64-encode the 32 bytes.
Questions and answers
Must I wait for clearance before hashing the next invoice?
No. The technical guidelines say ZATCA's stamp does not change the hash, so documents can be issued without waiting.
Related pages
- KSA-13 Previous invoice hash (PIH)
- KSA-15 Cryptographic stamp
- KSA-14 QR code
- BR-KSA-26 · The previous invoice hash must be a base64 SHA-256 computed the standard's way.
- BR-KSA-61 · Every document must contain the previous invoice hash.
Related concepts
- XML canonicalization (C14N 1.1) before hashingTurning XML text into one standard form before hashing, so the same document gives the same fingerprint on every system.
- The previous invoice hash (PIH) and the document chainEach document carries the hash of the one before it from the same device, so documents form a chain in which any deletion or change shows.
- The cryptographic stamp (digital signature)An ECDSA signature in XAdES form over the document hash and signing properties, made with a registered device key and a ZATCA-issued certificate.
E-invoicing in Saudi Arabia (FATOORA)
Sources
- Electronic Invoice XML Implementation Standard to the E-Invoicing resolution dated 2023-05-19 (v1.2) — ZATCA
- Security Features Implementation Standards to the E-Invoicing resolution dated 2023-05-19 (v1.2) — ZATCA
- E-invoicing Detailed Technical Guidelines (vVersion 2) — ZATCA
Checked on: 4 November 2026. What concerns JooDax is taken from the programs’ own code.