Skip to content
E-invoicing in Saudi Arabia (FATOORA)

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

Built

The 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

  1. Remove the ext:UBLExtensions block.
  2. Remove the AdditionalDocumentReference whose ID is QR.
  3. Remove cac:Signature.
  4. Drop the XML declaration and canonicalize with C14N 1.1.
  5. 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

Related concepts

E-invoicing in Saudi Arabia (FATOORA)

Sources

  1. Electronic Invoice XML Implementation Standard to the E-Invoicing resolution dated 2023-05-19 (v1.2) — ZATCA
  2. Security Features Implementation Standards to the E-Invoicing resolution dated 2023-05-19 (v1.2) — ZATCA
  3. E-invoicing Detailed Technical Guidelines (vVersion 2) — ZATCA

Checked on: 4 November 2026. What concerns JooDax is taken from the programs’ own code.