DFeSigner.NET
.NET library for digitally signing Brazilian electronic fiscal documents (DF-e) using X.509 certificates. Supports NF-e, NFC-e, CT-e and MDF-e XML signatures following official SEFAZ standards.
Overview
DFeSigner.NET is a C# library designed to simplify the process of digitally signing Brazilian electronic fiscal documents (DF-e).
The library integrates with X.509 digital certificates (A1 or A3) and uses the .NET XML cryptography APIs to generate valid XML digital signatures required by SEFAZ systems.
Its modular architecture allows easy extension for additional document types in the future.
Supported Documents
- NF-e — Nota Fiscal Eletrônica (model 55)
- NFC-e — Nota Fiscal de Consumidor Eletrônica (model 65)
- CT-e — Conhecimento de Transporte Eletrônico (model 57)
- MDF-e — Manifesto Eletrônico de Documentos Fiscais (model 58)
Features
- Digital signing of DF-e XML documents
- Signature validation to verify document integrity
- Support for X.509 digital certificates (A1 and A3)
- Document type validation before signing
- Robust error handling with custom exceptions
- Unit tests using xUnit
- Modular architecture for extensibility
Technologies
- .NET / C#
- System.Xml
- System.Security.Cryptography.Xml
- X509Certificates
- xUnit
Example Usage
using DFeSigner.Core.Signers;
using System.Security.Cryptography.X509Certificates;
X509Certificate2 certificate = new X509Certificate2("certificado.pfx", "senha");
string xmlContent = File.ReadAllText("nfe.xml");
NFeXmlSigner signer = new NFeXmlSigner();
string signedXml = signer.Sign(xmlContent, certificate);
bool isValid = signer.IsSignatureValid(signedXml);
Error Handling
- Invalid certificate or missing private key
- Invalid XML format
- Unexpected document model
- Missing signature elements
- Missing reference IDs
License
This project is licensed under the MIT License.
© 2025 Tiago Ávila Saldanha