Mexican digital tax invoices are signed with an X.509 certificate issued by the SAT. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/eclipxe13/CfdiUtils/llms.txt
Use this file to discover all available pages before exploring further.
CfdiUtils\Certificado\Certificado class loads these certificate files, parses them with PHP’s OpenSSL extension, and exposes all the fields you need — RFC, serial number, validity dates, public key — through a clean getter API.
The class accepts both PEM format (plain Base64 text with -----BEGIN CERTIFICATE----- headers) and DER/CER binary format. When given a CER binary file, the class converts it to PEM internally before parsing; your code does not need to handle the conversion.
Available Getters
Once a certificate is loaded, the following methods are available:| Method | Return type | Description |
|---|---|---|
getRfc() | string | RFC (Registro Federal de Contribuyentes) embedded in the certificate’s subject |
getName(bool $trimSuffix = false) | string | Razón Social (business name) from the certificate subject; pass true to strip the régimen de capital suffix |
getNameWithoutRegimenCapitalSuffix() | string | Business name with common capital regime suffixes removed (e.g. “SA DE CV”) |
getCertificateName() | string | Full certificate name string as returned by OpenSSL |
getSerial() | string | Serial number in ASCII format — this is the value required by the NoCertificado attribute in CFDI |
getSerialObject() | SerialNumber | A cloned SerialNumber object for converting between ASCII, hexadecimal, and decimal formats |
getValidFrom() | int | Unix timestamp from which the certificate is valid |
getValidTo() | int | Unix timestamp until which the certificate is valid |
getPubkey() | string | Public key in PEM format |
getPemContents() | string | Full PEM representation of the certificate |
getPemContentsOneLine() | string | PEM certificate body as a single line (useful for embedding in CFDI XML) |
getFilename() | string | The file path used when loading (empty string if loaded from raw contents) |
Load a Certificate
InstantiateCertificado with the path to a CER or PEM file:
Verify a Signature
verify() checks that a given binary signature over a data string is valid according to this certificate’s public key. This is exactly the operation used when validating the CFDI sello against the Cadena de Origen.
The plaintext data that was signed (e.g., the Cadena de Origen string).
The raw binary signature to verify (decode from Base64 before passing).
The OpenSSL digest algorithm constant. CFDI uses
OPENSSL_ALGO_SHA256.Check That a Private Key Belongs to This Certificate
belongsTo() uses OpenSSL to confirm that a given PEM private key file is the cryptographic counterpart of this certificate’s public key. Use this before signing to make sure the key and certificate are a matching pair.
Absolute path to a PEM-format private key file. The private key must already be in PEM format — convert from KEY (PKCS#8 DER) first if needed.
Optional passphrase for an encrypted PEM key.
Serial Number Formats
The SAT requires the ASCII representation of the serial number in theNoCertificado attribute, but you may need hexadecimal or decimal for logging or other systems. Obtain a SerialNumber object with getSerialObject():
getSerialObject() returns a clone, not the internal instance, because SerialNumber is mutable. Future versions of CfdiUtils will make SerialNumber immutable and return the internal instance directly.NodeCertificado: Extract a Certificate from a CFDI Node
When reading an existing CFDI, the certificate is embedded in thecfdi:Comprobante@Certificado attribute as Base64. CfdiUtils\Certificado\NodeCertificado extracts, decodes, and optionally saves it.
| Method | Description |
|---|---|
extract(): string | Reads Certificado attribute from the node and decodes it from Base64 |
save(string $filename): void | Writes the extracted binary certificate to a file |
obtain(): Certificado | Decodes the certificate from the Certificado attribute and returns a loaded Certificado instance |