<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: sasan dadar</title>
    <description>The latest articles on DEV Community by sasan dadar (@vorlex-taxiran).</description>
    <link>https://dev.to/vorlex-taxiran</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4244264%2Ff54d5797-2864-4a90-8a14-dd03ca89584f.png</url>
      <title>DEV Community: sasan dadar</title>
      <link>https://dev.to/vorlex-taxiran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vorlex-taxiran"/>
    <language>en</language>
    <item>
      <title>Implementing Iran's Moadian E-Invoicing Cryptography: RSA-2048 CSR (OID 2.5.4.97), Verhoeff TaxID, and Stuff ID Validation</title>
      <dc:creator>sasan dadar</dc:creator>
      <pubDate>Sat, 14 Nov 2026 10:02:24 +0000</pubDate>
      <link>https://dev.to/vorlex-taxiran/implementing-irans-moadian-e-invoicing-cryptography-rsa-2048-csr-oid-25497-verhoeff-taxid-56c2</link>
      <guid>https://dev.to/vorlex-taxiran/implementing-irans-moadian-e-invoicing-cryptography-rsa-2048-csr-oid-25497-verhoeff-taxid-56c2</guid>
      <description>&lt;p&gt;published: true&lt;br&gt;
tags: python, cryptography, fintech, erp&lt;/p&gt;

&lt;p&gt;Building an accounting or ERP integration for Iran's National Tax Administration (Moadian / سامانه مودیان) comes with strict cryptographic and schema validation requirements. Even a minor mismatch in the certificate subject, payload signing, or checksum digit results in gateway rejections such as Error 4103 or Error 0300101.&lt;/p&gt;

&lt;p&gt;Here is a practical engineering breakdown of the three core components required for compliant e-invoicing, along with open reference tools we use at VORLEX.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Generating an RSA-2048 Key Pair and CSR with OID 2.5.4.97&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before submitting any electronic invoice, the taxpayer's portal (my.tax.gov.ir) requires a 2048-bit RSA public key to issue a 6-character Unique Fiscal Memory ID. Unlike generic TLS certificates, the CSR subject must include the organizationIdentifier attribute (OID 2.5.4.97) containing the 10-digit National ID (for individuals) or 11-digit National ID (for legal entities).&lt;/p&gt;

&lt;p&gt;In Python (cryptography), you can generate a compliant CSR like this:&lt;/p&gt;

&lt;p&gt;from cryptography import x509&lt;br&gt;
from cryptography.hazmat.primitives import hashes, serialization&lt;br&gt;
from cryptography.hazmat.primitives.asymmetric import rsa&lt;br&gt;
from cryptography.x509.oid import NameOID, ObjectIdentifier&lt;/p&gt;

&lt;p&gt;private_key = rsa.generate_private_key(public_exponent=65537, key_size=2048)&lt;/p&gt;

&lt;p&gt;subject = x509.Name([&lt;br&gt;
    x509.NameAttribute(NameOID.COUNTRY_NAME, "IR"),&lt;br&gt;
    x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Vorlex Trading Co"),&lt;br&gt;
    x509.NameAttribute(ObjectIdentifier("2.5.4.97"), "14001234567"),&lt;br&gt;
    x509.NameAttribute(NameOID.COMMON_NAME, "Vorlex Trading Co"),&lt;br&gt;
])&lt;/p&gt;

&lt;p&gt;csr = x509.CertificateSigningRequestBuilder().subject_name(subject).sign(&lt;br&gt;
    private_key, hashes.SHA256()&lt;br&gt;
)&lt;/p&gt;

&lt;p&gt;If you need to quickly generate or verify test keys in the browser without running OpenSSL scripts, you can use the free Moadian CSR &amp;amp; Key Pair Generator.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Constructing the 22-Character TaxID with Verhoeff Checksum&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Every invoice requires a globally unique 22-character taxid:&lt;/p&gt;

&lt;p&gt;Characters 1–6: Fiscal Memory ID (6 alphanumeric chars)&lt;/p&gt;

&lt;p&gt;Characters 7–11: Days elapsed since 1970-01-01 (5 base-36/hex digits)&lt;/p&gt;

&lt;p&gt;Characters 12–21: Invoice serial number (inno, 10 hex chars)&lt;/p&gt;

&lt;p&gt;Character 22: Checksum digit computed via the Verhoeff algorithm&lt;/p&gt;

&lt;p&gt;Before computing the Verhoeff digit, each alphanumeric character in the 21-character prefix is mapped to its numeric ASCII/decimal representation. You can inspect and verify any 22-character identifier using the TaxID Verhoeff Structure Validator.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Resolving 13-Digit Stuff ID Codes and VAT Rates&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A frequent cause of invoice rejection (Error 0304401 and Error 0303301) is a mismatch between the 13-digit commodity/service code (sstid) and the official VAT rate published in stuffid.tax.gov.ir.&lt;/p&gt;

&lt;p&gt;Because the official catalog contains over 200,000 rows, indexing it into a lightweight SQLite/FTS5 store allows sub-20ms lookups during invoice entry. For quick manual verification of specific 13-digit codes and their official VAT percentages, you can query the Stuff ID 13-Digit Catalog Finder.&lt;/p&gt;

&lt;p&gt;Implementing proper PKCS#1 v1.5 JWS signing, RSA-OAEP-SHA256 payload encryption, Verhoeff TaxID generation, and pre-flight Stuff ID VAT alignment eliminates over 90% of gateway rejections before an invoice ever leaves your ERP.&lt;/p&gt;

</description>
      <category>fintech</category>
      <category>python</category>
      <category>security</category>
    </item>
  </channel>
</rss>
