Sign an XML file

Namespace:  FirmaSAT
Assembly:  diFirmaSatNet (in diFirmaSatNet.dll) Version: 10.50.0.29531

Syntax

C#
public static int SignXml(
	string newFile,
	string baseFile,
	string keyFile,
	string password,
	string certFile,
	SignOptions signOpts
)
Visual Basic (Declaration)
Public Shared Function SignXml ( _
	newFile As String, _
	baseFile As String, _
	keyFile As String, _
	password As String, _
	certFile As String, _
	signOpts As SignOptions _
) As Integer

Parameters

newFile
Type: System..::.String
Name of new file to be created
baseFile
Type: System..::.String
Name of base XML file to be signed (or a string containing XML data)
keyFile
Type: System..::.String
Name of private key file
password
Type: System..::.String
Password
certFile
Type: System..::.String
Name of X.509 certificate file to be included in output XML (optional)
signOpts
Type: FirmaSAT..::.SignOptions
Options for output format (optional)

Return Value

0 if successful or non-zero error code if failed

Remarks

This will create an output XML document copied from the input with the Sello node overwritten by a new signature value. Any existing file called newFile will be overwritten without warning; however, the input and output files can be the same.

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.

Examples

CopyC#
int n = Sat.SignXml("cfdv40-signed_new.xml", "cfdv40-ejemplo.xml", "emisor.key", "12345678a", "emisor.cer");

See Also