Signing Simplified Invoice

I am struggling with signing simplified invoices and generating proper QR code. Before signing, I extracted the X509 certificate from the PCSID token and generated Certificate Hash. I also extracted the hex publickey from the certificate.

Following the documentation, I did the following:

  1. Generate complete XML
  2. Remove ext:UBLExtension, QRCode and Signature
  3. Generate hash from invoice and sign with privatekey. SHA-256 → base64
  4. Added the following values following the XPath given in documentation:
    (a) …CertDigest/DigestValue: Certificate Hash
    (b) …SignedSignatureProperties/SigningTime: current date/time ISO string
    (c) …IssuerSerial/X509IssuerName: “CN=PRZEINVOICESCA4-CA, DC=extgazt, DC=gov, DC=local” (taken from certificate.)
    (d) …IssuerSerial/X509SerialNumber: taken from certificate.
  5. Copied SignedProperties tag and its contents, hashed and encoded to base64
  6. Added these to XML as below:
    (a) …Signature/SignatureValue: signed invoice hash
    (b) …X509Data/X509Certificate: Certificate Hash (is this correct or I should include the full certificate?)
    (c) …SignedInfo/Reference[@SignedProperties]/DigestValue: SignedProperties Hash
    (d) …SignedInfo/Reference[@Id=‘invoiceSignedData]/DigestValue: invoice hash

I then generated the QR code using:
Tag 7: signed invoice hash
Tag 8: publickey extracted from privatekey
Tag 9: publickey extracted from X509 certificate

I am getting the errors: wrong invoice certificate, signature error null pointer exception and invalid QR.

Any help in pointing me in the right direction would be greatly appreciated. It would nice if somebody could share a valid example xml of simplified invoice. Thank you for your help.

Dear @naval

Thanks for reaching out,

Please ensure to review the below signing docs, Additionally, please refer to the following path after installing the latest version of our SDK which is 3.4.1 and you will find a valid XML samples for (simplified, simplified Credit, and simplified Debit)
zatca-einvoicing-sdk-Java-238-R3.4.1\Data\Samples\Simplified

Signing process:
SigningProcessUpdated.pdf (927.7 KB)

Thanks,
Ibrahem Daoud.