A .NET interface for FirmaSAT
Get additional information about the core DLL module.
public static string Comments()
Public Shared Function Comments As String
Console.WriteLine(General.Comments());
// Licensed Developer Edition | Edicion de Desarrollador Licenciado.
Get date and time the core DLL module was last compiled.
public static string CompileTime()
Public Shared Function CompileTime As String
Console.WriteLine(General.CompileTime()); // Feb 28 2021 18:29:46
Look up error code.
public static string ErrorLookup( int errCode )
Public Shared Function ErrorLookup ( _ errCode As Integer _ ) As String
Console.WriteLine(General.ErrorLookup(-10)); // Required data not found/Datos necesarios no encontrados (MISSING_ERROR)
Return an error message string for the last error.
public static string FormatErrorMessage( int errCode )
Public Shared Function FormatErrorMessage ( _ errCode As Integer _ ) As String
// Error (-28): XML restriction is violated/XML restriccion es violada (XML_FACET_ERROR): // Bad attribute/atributo mal [iedu:instEducativas/@CURP] (line 30): // 'JUAN01010101GTOHMD0' is too long/es demasiado largo, maximum length/longitud maxima=18
Retrieve the last error message.
public static string LastError()
Public Shared Function LastError As String
int n = Sat.ValidateXml("cfdv33a-badspec.xml"); Console.WriteLine("Sat.ValidateXml returns {0}", n); // Sat.ValidateXml returns -27 Console.WriteLine(General.ErrorLookup(n)); // Invalid XML format/No valido formato XML (BAD_XML_ERROR) Console.WriteLine(General.LastError()); // XML validation error/Error al validar XML: Required attribute 'Importe' missing for element 'cfdi:Concepto' (Line/numero de linea: 12); // XML validation error/Error al validar XML: Required attribute 'Importe' missing for element 'cfdi:Concepto' (Line/numero de linea: 13)
Get licence type.
public static char LicenceType()
Public Shared Function LicenceType As Char
Get full path name of core diFirmaSat DLL module.
public static string ModuleName()
Public Shared Function ModuleName As String
Console.WriteLine(General.ModuleName()); // C:\WINDOWS\SYSTEM32\diFirmaSAT2.dll
Get the platform for which the core native DLL was compiled.
public static string Platform()
Public Shared Function Platform As String
Return version number of core diFirmaSat DLL.
public static int Version()
Public Shared Function Version As Integer
int n = General.Version(); Console.WriteLine("Version = {0}", n); // Version = 90215
Replace any non-ASCII characters in an XML document (as a byte array) with XML character references (where permitted).
public static string Asciify( byte[] xmlData )
Public Shared Function Asciify ( _ xmlData As Byte() _ ) As String
byte[] b = File.ReadAllBytes("cfdv40-ejemplo.xml"); string s = Sat.Asciify(b); Console.WriteLine(s); // <?xml version="1.0"?> // <cfdi:Comprobante ... > // <cfdi:Emisor Rfc=" AAA010101AAA" Nombre="Esta es una demostración" RegimenFiscal="622"></cfdi:Emisor> // ... [etc]
Replace non-ASCII characters in an XML document with XML numeric character references (where permitted).
public static string Asciify( string xmlFile )
Public Shared Function Asciify ( _ xmlFile As String _ ) As String
In certain cases, some characters in an XML document cannot be replaced by a numeric character reference, for example where they are used in an element or attribute name, such as Año="2016". In these cases, they are left as UTF-8-encoded characters.
Console.WriteLine(Sat.Asciify("cfdv40-ejemplo.xml"); // <?xml version="1.0" ?> // <cfdi:Comprobante ... > // <cfdi:Emisor Rfc=" AAA010101AAA" Nombre="Esta es una demostración" RegimenFiscal="622"></cfdi:Emisor> // ... [etc]
Verify that the public key in an X.509 certificate matches the private key.
public static int CheckKeyAndCert( string keyFile, string password, string certFile )
Public Shared Function CheckKeyAndCert ( _ keyFile As String, _ password As String, _ certFile As String _ ) As Integer
int n = Sat.CheckKeyAndCert("emisor.key", "12345678a", "emisor.cer"); Console.WriteLine("Sat.CheckKeyAndCert returns {0}", n); // Sat.CheckKeyAndCert returns 0 // Cert and key do not match ... n = Sat.CheckKeyAndCert("emisor.key", "12345678a", "pac.cer"); Console.WriteLine("Sat.CheckKeyAndCert returns {0}", n); // Sat.CheckKeyAndCert returns -21 Console.WriteLine(General.ErrorLookup(n)); // Match not found/No se pudo encontrar datos coincidente (NO_MATCH_ERROR) Console.WriteLine(General.LastError()); // Private key does not match key in certificate/La clave privada no coincide con la clave del certificado
Return default digest (hash) algorithm for the XML document type.
public static string DefaultDigestAlg( string xmlFile )
Public Shared Function DefaultDigestAlg ( _ xmlFile As String _ ) As String
Console.WriteLine(Sat.DefaultDigestAlg("cfdv40-ejemplo.xml")); // SHA-256
Extract message digest from the signature (sello) in an XML file.
public static string ExtractDigestFromSignature( string xmlFile, string certFile )
Public Shared Function ExtractDigestFromSignature ( _ xmlFile As String, _ certFile As String _ ) As String
Console.WriteLine(Sat.ExtractDigestFromSignature("cfdv40-ejemplo-signed-tfd.xml")); // 0FF1274E51FBB090489588D832BB1B5B36543302DECBB0A5490839B8C99E8755
Add UTF-8 byte order mark (BOM) to a file if not already present.
public static int FixBom( string outputFile, string inputFile )
Public Shared Function FixBom ( _ outputFile As String, _ inputFile As String _ ) As Integer
int n = Sat.FixBom("cfdv40_new-signed-with-BOM.xml", "cfdv40-signed-nobom.xml"); Console.WriteLine("Sat.FixBom returns {0}", n); // Read in new file as bytes, truncate, and display first 3 bytes: expecting EF-BB-BF byte[] b = File.ReadAllBytes("cfdv40_new-signed-with-BOM.xml"); Array.Resize(ref b, 3); Console.WriteLine(BitConverter.ToString(b)); // EF-BB-BF
Get certificate data as a base64 string.
public static string GetCertAsString( string fileName )
Public Shared Function GetCertAsString ( _ fileName As String _ ) As String
Console.WriteLine(Sat.GetCertAsString("emisor.cer")); // MIIF+TCCA+GgAwIBAgIUMzAwMDEwMDAwMDAzMDAw ...
Get expiry date of the X.509 certificate in ISO time format.
public static string GetCertExpiry( string fileName )
Public Shared Function GetCertExpiry ( _ fileName As String _ ) As String
Console.WriteLine(Sat.GetCertExpiry("emisor.cer")); // 2021-05-18T03:54:56Z
Get serial number of the X.509 certificate in "special" SAT format.
public static string GetCertNumber( string fileName )
Public Shared Function GetCertNumber ( _ fileName As String _ ) As String
// From certificate file directly Console.WriteLine(Sat.GetCertNumber("emisor.cer")); // 30001000000300023708 // From embedded Certificado attribute Console.WriteLine(Sat.GetCertNumber("cfdv40-ejemplo-signed-tfd.xml")); // 30001000000300023708
Get start date of the X.509 certificate in ISO time format.
public static string GetCertStart( string fileName )
Public Shared Function GetCertStart ( _ fileName As String _ ) As String
Console.WriteLine(Sat.GetCertStart("emisor.cer")); // 2017-05-18T03:54:56Z
Get private key data as a base64 string suitable for a llaveCertificado element in a Cancelacion XML document
public static string GetKeyAsString( string fileName, string password, KeyOption keyOpt )
Public Shared Function GetKeyAsString ( _ fileName As String, _ password As String, _ keyOpt As KeyOption _ ) As String
Console.WriteLine(Sat.GetKeyAsString("emisor.key", "12345678a")); // PFJTQUtleVZhbHVlPjxNb2R1bHVzP ... WYWx1ZT4=
Console.WriteLine(Sat.GetKeyAsString("emisor.key", "12345678a", KeyOption.EncryptedPEM)); // -----BEGIN ENCRYPTED PRIVATE KEY----- // MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIAgEAAoIBAQACAggA // ... rbw= // -----END ENCRYPTED PRIVATE KEY-----
Extract attribute data from an XML file.
public static string GetXmlAttribute( string xmlFile, string attributeName, string elementName )
Public Shared Function GetXmlAttribute ( _ xmlFile As String, _ attributeName As String, _ elementName As String _ ) As String
XPath expression: Alternatively, specify an path expression in elementName using the "/" and "//" operators and optional predicate [N] where N is a positive integer. For example "/Comprobante/Emisor" or "//Concepto[2]//Retencion[3]". This is a simplified form of XPath that selects the first occurrence of the element matching the path expression (whereas XPath would select all matching elements). Path expressions must start with a "/" or "//" and must not end with a "/". No other XPath function or operator is accepted. Do not use namespace prefixes (e.g. "cfdi:") in the path expression.
Simplified Xpath syntax:
To test for the existence of an element, set attributeName="". This will return the name of the element if it exists, or "!NO MATCH!" if not found. This message can be changed using SetXmlNoMatch(String).
Console.WriteLine(Sat.GetXmlAttribute("cfdv40-ejemplo.xml", "Nombre", "cfdi:Emisor")); // Esta es una demostración
Insert certificate information into an XML document and output to a new file.
public static int InsertCert( string newFile, string baseFile, string certFile )
Public Shared Function InsertCert ( _ newFile As String, _ baseFile As String, _ certFile As String _ ) As Integer
// Take an XML file without a NoCertificado... string fname = cfdv40-ejemplo-nocertnum.xml"; Console.WriteLine("Start file '{0}'.NoCertificado=[{1}]", fname, Sat.GetXmlAttribute(fname, "NoCertificado", "cfdi:Comprobante")); Console.WriteLine("Start file '{0}'.Certificado={1} bytes", fname, Sat.GetXmlAttribute(fname, "Certificado", "cfdi:Comprobante").Length); // Insert certificate details into intermediate file... string interfile = "cfdv40_new-base-pluscert.xml"; int n = Sat.InsertCert(interfile, fname, "emisor.cer"); Console.WriteLine("Sat.InsertCert() returns {0} (expecting 0)", n); Debug.Assert(0 == n, "Sat.InsertCert failed"); Console.WriteLine("Inter file '{0}'.NoCertificado=[{1}]", interfile, Sat.GetXmlAttribute(interfile, "NoCertificado", "cfdi:Comprobante")); Console.WriteLine("Inter file '{0}'.Certificado={1} bytes", interfile, Sat.GetXmlAttribute(interfile, "Certificado", "cfdi:Comprobante").Length); // Start file 'cfdv40-ejemplo-nocertnum.xml'.NoCertificado=[] // Start file 'cfdv40-ejemplo-nocertnum.xml'.Certificado=0 bytes // Sat.InsertCert() returns 0 (expecting 0) // Inter file 'cfdv40_new-base-pluscert.xml'.NoCertificado=[30001000000300023708] // Inter file 'cfdv40_new-base-pluscert.xml'.Certificado=1836 bytes
Insert certificate information into an XML document (as a byte array) and output to memory.
public static byte[] InsertCertToBytes( byte[] xmlData, string certFile )
Public Shared Function InsertCertToBytes ( _ xmlData As Byte(), _ certFile As String _ ) As Byte()
// Pass input XML data as a byte array byte[] xmlArr = File.ReadAllBytes("cfdv40-ejemplo-nocertnum.xml"); string cerStr = Sat.GetCertAsString("emisor.cer"); byte[] b = Sat.InsertCertToBytes(xmlArr, cerStr); Console.WriteLine(System.Text.Encoding.UTF8.GetString(b)); // <cfdi:Comprobante // ... // NoCertificado="30001000000300023708" Sello="" Certificado="MIIF+TCCA+GgAwIBAgIU ...
Insert certificate information into an XML document (as a file) and output to memory.
public static byte[] InsertCertToBytes( string xmlFile, string certFile )
Public Shared Function InsertCertToBytes ( _ xmlFile As String, _ certFile As String _ ) As Byte()
// Pass input XML data as a string string xmlStr = File.ReadAllText("cfdv40-ejemplo-nocertnum.xml"); string cerStr = Sat.GetCertAsString("emisor.cer"); byte[] b = Sat.InsertCertToBytes(xmlStr, cerStr); Console.WriteLine(System.Text.Encoding.UTF8.GetString(b)); // <cfdi:Comprobante // ... // NoCertificado="30001000000300023708" Sello="" Certificado="MIIF+TCCA+GgAwIBAgIU ...
Retrieve the last error message.
public static string LastError()
Public Shared Function LastError As String
// Attempt to sign but input file does not comply with CFDi specifications int n = satSignXml("cfdv33a-out.xml", "cfdv33a-badspec.xml", "emisor.key", "12345678a", "emisor.cer"); Console.WriteLine("Error {0}: {1}", n, Sat.ErrorLookup(n)); // Error -10: Required data not found/Datos necesarios no encontrados (MISSING_ERROR) Console.WriteLine(Sat.LastError()); // Attribute 'Importe' is mandatory/Atributo es obligatorio
Form message digest of piped string (cadena) from an XML file.
public static string MakeDigestFromXml( string xmlFile )
Public Shared Function MakeDigestFromXml ( _ xmlFile As String _ ) As String
Console.WriteLine(Sat.MakeDigestFromXml("cfdv40-ejemplo-signed-tfd.xml")); // 0ff1274e51fbb090489588d832bb1b5b36543302decbb0a5490839b8c99e8755
Create the piped string (cadena) from an XML file.
public static string MakePipeStringFromXml( string xmlFile )
Public Shared Function MakePipeStringFromXml ( _ xmlFile As String _ ) As String
string s = Sat.MakePipeStringFromXml("cfdv40-ejemplo.xml"); Console.WriteLine(s); // ||3.3|A|123ABC|2017-12-04T01:23:59|02|...[cut]...||
Create signature as a base64 string from data in an XML file ready to be inserted as a sello node.
public static string MakeSignatureFromXml( string xmlFile, string keyFile, string password )
Public Shared Function MakeSignatureFromXml ( _ xmlFile As String, _ keyFile As String, _ password As String _ ) As String
string s = Sat.MakeSignatureFromXml("cfdv40-ejemplo.xml", "emisor.key", "12345678a"); Console.WriteLine(s); // JQJd6rbiMZj1tZVb1Ta8l88bE7pTDm/aAl ...
Save keyfile with a new password.
public static int NewKeyFile( string newFile, string newPassword, string keyFile, string keyPassword, KeyFormat format )
Public Shared Function NewKeyFile ( _ newFile As String, _ newPassword As String, _ keyFile As String, _ keyPassword As String, _ format As KeyFormat _ ) As Integer
string password = "12345678a"; string newpassword = "password123"; int n = Sat.NewKeyFile("emisor_new.pem", newpassword, "emisor.key", password, KeyFormat.PEM); Debug.Assert(n == 0, "Sat.NewKeyFile failed"); Console.WriteLine(File.ReadAllText("emisor_new.pem")); // -----BEGIN ENCRYPTED PRIVATE KEY----- // MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIn2sl+Cj3VtgCAggA ... // -----END ENCRYPTED PRIVATE KEY-----
Query an X.509 certificate.
public static string QueryCert( string fileName, Query query )
Public Shared Function QueryCert ( _ fileName As String, _ query As Query _ ) As String
Modify the string returned when GetXmlAttribute(String, String, String) fails to find a match.
public static void SetXmlNoMatch( string value )
Public Shared Sub SetXmlNoMatch ( _ value As String _ )
// Show default NoMatch string Console.WriteLine(Sat.XmlNoMatch()); // !NO MATCH! string fname = "cfdv40-ejemplo-signed-tfd.xml"; // Look for element that isn't there Console.WriteLine(Sat.GetXmlAttribute(fname, "", "/Comprobante/notthere")); // !NO MATCH! // Set a new NoMatch string Sat.SetXmlNoMatch("##No coinciden##"); Console.WriteLine(Sat.GetXmlAttribute(fname, "", "/Comprobante/notthere")); // ##No coinciden##
Sign an XML file
public static int SignXml( string newFile, string baseFile, string keyFile, string password, string certFile, SignOptions signOpts )
Public Shared Function SignXml ( _ newFile As String, _ baseFile As String, _ keyFile As String, _ password As String, _ certFile As String, _ signOpts As SignOptions _ ) As Integer
If a certificate file szCertFile is specified then the Certificado and NoCertificado nodes will be overwritten in the output file with the values in the certificate file. If a certificate file is not specified then the Certificado value in the XML will be used.
A version 4 CFDi document to be signed must use the "cfdi:" namespace prefix. For CFD v4 the NoCertificado attribute in the input must be set to the correct certificate serial number before signing. In a Retenciones document you must set the CertNum attribute before signing. In a ControlesVolumetricos document you must set both the noCertificado and certificado attributes before signing.int n = Sat.SignXml("cfdv40-signed_new.xml", "cfdv40-ejemplo.xml", "emisor.key", "12345678a", "emisor.cer");
Sign an XML file with extended options [deprecated].
[ObsoleteAttribute("Use Sat.SignXml with optional SignOptions parameter")] public static int SignXmlEx( string newFile, string xmlFile, string keyFile, string password, string certFile, SignOptions signOpts )
<ObsoleteAttribute("Use Sat.SignXml with optional SignOptions parameter")> _ Public Shared Function SignXmlEx ( _ newFile As String, _ xmlFile As String, _ keyFile As String, _ password As String, _ certFile As String, _ signOpts As SignOptions _ ) As Integer
int n = Sat.SignXmlEx(newname, fname, keyfile, password, certfile, SignOptions.BigFile);
Sign XML data writing output to a byte array.
public static byte[] SignXmlToBytes( byte[] xmlData, string keyFile, string password, string certFile, SignOptions signOpts )
Public Shared Function SignXmlToBytes ( _ xmlData As Byte(), _ keyFile As String, _ password As String, _ certFile As String, _ signOpts As SignOptions _ ) As Byte()
string password = "12345678a"; string keyStr = Sat.GetKeyAsString("emisor.key", password, KeyOption.EncryptedPEM); string cerStr = Sat.GetCertAsString("emisor.cer"); byte[] xmlArr = File.ReadAllBytes("cfdv40-ejemplo.xml"); byte[] xmlArrSigned = Sat.SignXmlToBytes(xmlArr, keyStr, password, cerStr, 0); Console.WriteLine(System.Text.Encoding.UTF8.GetString(xmlArrSigned)); // <?xml version="1.0" encoding="UTF-8"?> // <cfdi:Comprobante xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cfdi="http://www.sat.gob.mx/cfd/3" ...
Sign XML file writing output to a byte array.
public static byte[] SignXmlToBytes( string xmlFile, string keyFile, string password, string certFile, SignOptions signOpts )
Public Shared Function SignXmlToBytes ( _ xmlFile As String, _ keyFile As String, _ password As String, _ certFile As String, _ signOpts As SignOptions _ ) As Byte()
byte[] b = Sat.SignXmlToBytes("cfdv40-ejemplo.xml", "emisor.key", "12345678a", "emisor.cer", SignOptions.Default); Console.WriteLine(System.Text.Encoding.UTF8.GetString(b)); // <?xml version="1.0" encoding="UTF-8"?> // <cfdi:Comprobante xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cfdi="http://www.sat.gob.mx/cfd/3" ...
Generate a Universally Unique IDentifier (UUID) compliant with RFC 4122.
public static string Uuid()
Public Shared Function Uuid As String
Console.WriteLine(Sat.Uuid());
// 343c6b13-4f69-4d2a-97e6-64cb770c7677
Validate an XML file against SAT specifications.
public static int ValidateXml( string xmlFile, XmlOption xmlOpt )
Public Shared Function ValidateXml ( _ xmlFile As String, _ xmlOpt As XmlOption _ ) As Integer
int n = Sat.ValidateXml("cfdv40-ejemplo.xml"); Console.WriteLine("Sat.ValidateXml returns {0}", n); // Sat.ValidateXml returns 0 int n = Sat.ValidateXml("cfdv40-iedu-badcurp.xml"); Console.WriteLine("Sat.ValidateXml returns {0}", n); // Sat.ValidateXml returns -28 Console.WriteLine(General.ErrorLookup(n)); // XML restriction is violated/XML restriccion es violada (XML_FACET_ERROR) Console.WriteLine(General.LastError()); // Bad attribute/atributo mal [iedu:instEducativas/@CURP] (line 30): // 'JUAN01010101GTOHMD0' is too long/es demasiado largo, maximum length/longitud maxima=18
// Input has valid XML form but an invalid facet error against SAT specifications // Using the "Loose" option validates that the XML form is still correct. int n = Sat.ValidateXml("cfdv40-iedu-badcurp.xml", XmlOption.Loose); Console.WriteLine("Sat.ValidateXml(Loose) returns {0}", n); // Sat.ValidateXml(Loose) returns 0
Verify the signature (sello) in an XML file.
public static int VerifySignature( string xmlFile, string certFile )
Public Shared Function VerifySignature ( _ xmlFile As String, _ certFile As String _ ) As Integer
Console.WriteLine(Sat.VerifySignature("cfdv40-ejemplo-signed.xml")); // 0 Console.WriteLine(Sat.VerifySignature("cfdv40-badsig.xml")); // -15 Console.WriteLine(General.ErrorLookup(-15)); // Decryption error/De error de descifrado (DECRYPT_ERROR)
Create PFX (PKCS-12) file in PEM format suitable for a Cancelacin.
public static int WritePfxFile( string pfxFile, string pfxPassword, string keyFile, string keyPassword, string certFile, PfxFormat pfxFormat )
Public Shared Function WritePfxFile ( _ pfxFile As String, _ pfxPassword As String, _ keyFile As String, _ keyPassword As String, _ certFile As String, _ pfxFormat As PfxFormat _ ) As Integer
string password = "12345678a"; string newpassword = "clavedesalida"; int n = Sat.WritePfxFile("archivo_new-pfx.txt", newpassword, "emisor.key", password, "emisor.cer"); Debug.Assert(n == 0, "Sat.WritePfxFile failed"); Console.WriteLine(File.ReadAllText("archivo_new-pfx.txt")); // MIIMOQIBAzCCC/8GCSqGSIb3DQEHAaCCC/AEggvsMIIL6DCCBp8GCSqGSIb3DQEH ...
Error message returned when GetXmlAttribute(String, String, String) fails to find a match
public static string XmlNoMatch()
Public Shared Function XmlNoMatch As String
Console.WriteLine(Sat.XmlNoMatch());
// !NO MATCH!
Find version number of Comprobante element or ID number for other document types.
public static int XmlReceiptVersion( string xmlFile )
Public Shared Function XmlReceiptVersion ( _ xmlFile As String _ ) As Integer
Console.WriteLine(Sat.XmlReceiptVersion("cfdv40-ejemplo.xml")); // 40
Add a signed Timbre Fiscal Digital (TFD) element to a CFDI document.
public static int AddSignedTfd( string newFile, string inputFile, string keyFile, string password, string certFile )
Public Shared Function AddSignedTfd ( _ newFile As String, _ inputFile As String, _ keyFile As String, _ password As String, _ certFile As String _ ) As Integer
int n = Tfd.AddSignedTfd(newname, fname, keyfile, password, certfile); Console.WriteLine("Tfd.AddSignedTfd returns {0}", n); // 0 string s = Sat.GetXmlAttribute("cfdv40-ejemplo_signed.xml", "SelloSAT", "TimbreFiscalDigital"); // SelloSat=Qncw19SZ0w/uxkwCYkf/7V3DF3j28Jp1XyNVyqiyOreq0S ...
Extract message digest from the selloSAT node in Timbre Fiscal Digital of CFDI document.
public static string ExtractDigestFromSignature( string xmlFile, string certFile )
Public Shared Function ExtractDigestFromSignature ( _ xmlFile As String, _ certFile As String _ ) As String
Form message digest of cadena original del Timbre Fiscal Digital del SAT (TFD piped string) from CFDI XML file.
public static string MakeDigestFromXml( string xmlFile )
Public Shared Function MakeDigestFromXml ( _ xmlFile As String _ ) As String
Create the cadena original del Timbre Fiscal Digital del SAT (TFD piped string) from CFDI XML file.
public static string MakePipeStringFromXml( string xmlFile )
Public Shared Function MakePipeStringFromXml ( _ xmlFile As String _ ) As String
Create the selloSAT signature as a base64 string from TFD data in CFDI XML document.
public static string MakeSignatureFromXml( string xmlFile, string keyFile, string password )
Public Shared Function MakeSignatureFromXml ( _ xmlFile As String, _ keyFile As String, _ password As String _ ) As String
Verify the selloSAT signature in CFDI XML document.
public static int VerifySignature( string xmlFile, string certFile )
Public Shared Function VerifySignature ( _ xmlFile As String, _ certFile As String _ ) As Integer
Format for saved key files.
public enum KeyFormat
Public Enumeration KeyFormat
Member name | Description | |
---|---|---|
Default | Default = Binary | |
Binary | Binary DER-encoded | |
PEM | PEM Format |
Options for key output in Sat.GetKeyAsString().
public enum KeyOption
Public Enumeration KeyOption
Member name | Description | |
---|---|---|
Default | Default (unencrypted base64 string). | |
UnencryptedBase64 | Key as unencrypted base64 string suitable for Cancelacion element. | |
EncryptedPEM | Key as encrypted private key in PEM format suitable for input as a keyFile parameter. |
Options for PKCS12 (PFX) output in Sat.WritePfxFile().
public enum PfxFormat
Public Enumeration PfxFormat
Member name | Description | |
---|---|---|
Default | Default (plain base64 suitable for Cancelacion element). | |
Base64 | PFX data as plain base64. | |
PEM | PKCS12 PEM textual form = same as Base64 but with PEM encapsulation -----BEGIN PKCS12----- ... -----END PKCS12----- | |
Binary | Binary DER form. |
Options for certificate query.
public enum Query
Public Enumeration Query
Member name | Description | |
---|---|---|
notAfter | Get certificate expiry date. | |
notBefore | Get certificate start date. | |
organizationName | Get organization name of issuer. Expecting "Servicio de Administración Tributaria" if issued by SAT | |
companyName | Get organization name of subject. This should be your company name. | |
rfc | Get RFC of subject. Expecting 12 or 13 characters if issued by SAT. | |
serialNumber | Get decoded serial number. Expecting 20 decimal digits. | |
sigAlg | Get algorithm used to sign certificate (e.g. "sha256WithRSAEncryption"). | |
keySize | Get size in bits of certificate's public key (e.g. "2048"). |
Options for signing XML.
[FlagsAttribute] public enum SignOptions
<FlagsAttribute> _ Public Enumeration SignOptions
Member name | Description | |
---|---|---|
Default | Default (add BOM, empty elements in form <foo></foo>). | |
NoBOM | Do not add byte-order mark (BOM) to file. | |
UseEmptyElements | Output empty elements in empty-element tag form <foo /> (default is start-end tag pair form <foo></foo>). | |
BigFile | Speed up the processing of large files. | |
OverrideReqd | Override strict checks for required nodes (advanced users). |
Options for XML validation.
public enum XmlOption
Public Enumeration XmlOption
Member name | Description | |
---|---|---|
Default | Default value (strict) | |
Strict | Enforce stricter XML restrictions (default in v5.0 and above). | |
Loose | Use looser restrictions on data types (default before v5.0). |