Assinar xml Nfse paulistana

Asked

Viewed 1,045 times

-2

I did a program in C# who signs the XML in batch of the legal note of Porto Alegre. Now the company in which I work opened a branch in São Paulo and I need to sign the XML batch of the São Paulo tax bill to declare services provided. I tried to use the same program I did and got an error:

"Malformed Reference element."

I noticed some differences between xmls. xml from São Paulo does not have the id attribute either in rps or batch tags. The id attribute is required for the Reference element that computes the signature. I tried to manually set the id, but gave the same error.

Another difference I noticed is that in the legal note of Porto Alegre there are elements "Infrps", and each one needs an element signature, with all the data of how the signature was made, such as the algorithm, etc. The batch also needs the Signature element. In the São Paulo invoice, the lot at the end of the file specifies the Signature element, but the RPS elements that are equivalent to the "Infrps" of the Porto Alegre legal note contain only a signature tag, with an encoding in base64 RPS element signature. I don’t know yet how to generate this signature.

From now on I appreciate any help.

Below is an example of how should be the xml batch of the invoice already signed in São Paulo:

<?xml version="1.0" encoding="UTF-8"?>
<PedidoEnvioLoteRPS xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"                         xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.prefeitura.sp.gov.br/nfe">
<Cabecalho Versao="1" xmlns="">
<CPFCNPJRemetente>
  <CNPJ>04642554000143</CNPJ>
</CPFCNPJRemetente>
<transacao>false</transacao>
<dtInicio>2007-01-20</dtInicio>
<dtFim>2007-01-20</dtFim>
<QtdRPS>2</QtdRPS>
<ValorTotalServicos>2000</ValorTotalServicos>
<ValorTotalDeducoes>200</ValorTotalDeducoes>
</Cabecalho>
<RPS xmlns="">
       <Assinatura>ro6Og7L5BMPpYZKXfSSITNe8U9C4a95P9dIspX8R0Okg1CRsA87N08Llaq+q6IVOGLhjGMkAELBIkQ8T0BGR3czgtJAuOcgMlOmGZlgziWAg3Kww3pFD+rYxE+DRgL2M5QXTaZEYwVNj0lZyJpt1nS9LHUqO7PB+ivYRk+ewUVA=</Assinatura>
<ChaveRPS>
  <InscricaoPrestador>31000000</InscricaoPrestador>
  <SerieRPS>LLLLL</SerieRPS>
  <NumeroRPS>1</NumeroRPS>
</ChaveRPS>
<TipoRPS>RPS-M</TipoRPS>
<DataEmissao>2007-01-20</DataEmissao>
<StatusRPS>N</StatusRPS>
<TributacaoRPS>T</TributacaoRPS>
<ValorServicos>1000</ValorServicos>
<ValorDeducoes>100</ValorDeducoes>
<CodigoServico>2658</CodigoServico>
<AliquotaServicos>0.05</AliquotaServicos>
<ISSRetido>false</ISSRetido>
<CPFCNPJTomador>
  <CPF>18564071878</CPF>
</CPFCNPJTomador>
<RazaoSocialTomador>PATRICIA TUPYNAMBA</RazaoSocialTomador>
<EnderecoTomador>
  <TipoLogradouro>R</TipoLogradouro>
  <Logradouro>Guararapes</Logradouro>
  <NumeroEndereco>495 A</NumeroEndereco>
  <ComplementoEndereco>ap 102</ComplementoEndereco>
  <Bairro>BROOKLIN PAULISTA</Bairro>
  <Cidade>3550308</Cidade>
  <UF>SP</UF>
  <CEP>4561000</CEP>
</EnderecoTomador>
<EmailTomador>[email protected]</EmailTomador>
<Discriminacao>Desenvolvimento de Web Site Pessoal</Discriminacao>
</RPS>
<RPS xmlns="">
            <Assinatura>jkTucEqcj8Qkes8RalHZW+p6Zc6weeqnPabOK7IHSkyVTO9reNqpMclEh8n6nHXSPGcn   svhQx4JWx/sK26IxVTOMKp3i41/1w3OyC9SvL0VPtzrARKQMEqTf2kqwu9skHMzw5d4T/jfjYLrp5n/Y    AbMqKQ5zaa4qAcY0A066OAc=</Assinatura>
<ChaveRPS>
  <InscricaoPrestador>31000000</InscricaoPrestador>
  <SerieRPS>LLLLL</SerieRPS>
  <NumeroRPS>2</NumeroRPS>
</ChaveRPS>
<TipoRPS>RPS-M</TipoRPS>
<DataEmissao>2007-01-20</DataEmissao>
<StatusRPS>N</StatusRPS>
<TributacaoRPS>T</TributacaoRPS>
<ValorServicos>1000</ValorServicos>
<ValorDeducoes>100</ValorDeducoes>
<ValorPIS>10</ValorPIS>
<ValorCOFINS>20</ValorCOFINS>
<ValorINSS>30</ValorINSS>
<ValorIR>40</ValorIR>
<ValorCSLL>50</ValorCSLL>
<CodigoServico>2658</CodigoServico>
<AliquotaServicos>0.05</AliquotaServicos>
<ISSRetido>false</ISSRetido>
<CPFCNPJTomador>
  <CNPJ>06215299000188</CNPJ>
</CPFCNPJTomador>
        <RazaoSocialTomador>Grixco Soluções</RazaoSocialTomador>
<EnderecoTomador>
  <TipoLogradouro>R</TipoLogradouro>
  <Logradouro>Augusta</Logradouro>
  <NumeroEndereco>01642</NumeroEndereco>
  <ComplementoEndereco>3 Andar</ComplementoEndereco>
  <Bairro>Cerqueira Cesar</Bairro>
  <Cidade>3550308</Cidade>
  <UF>SP</UF>
  <CEP>1304001</CEP>
</EnderecoTomador>
<Discriminacao>Manutenção de Sistema</Discriminacao>
</RPS>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
  <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
  <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
  <Reference URI="">
    <Transforms>
      <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
      <Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
    </Transforms>
    <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
    <DigestValue>AkHyCjCwkANg3aRAnltAXR1YQ4c=</DigestValue>
  </Reference>
</SignedInfo>   
<SignatureValue>IkLB0qfZLDuTNXNB83tXXsZ2TFNK9X0l7gq8jRCOcwhit059iF5gNHfmuM4NoUhyhZ+rC6UGn9lSMv1A35lofsplIuWUJO13yPtHsxaY6/rP9DTB4Ve3ihzwrEkpenANoEU1C5wLenX0lRtYc1k3fWeDmZUvv+b/M81pwoPBL8k=</SignatureValue>
<KeyInfo>
  <X509Data>
    <X509Certificate>MIIFUzCCBDugAwIBAgIQSUJS8pELZyjasDkgGzKm0TANBgkqhkiG9w0BAQUFADBuMQswCQYDVQQGEwJCUjETMBEGA1UEChMKSUNQLUJyYXNpbDEsMCoGA1UECxMjU2VjcmV0YXJpYSBkYSBSZWNlaXRhIEZlZGVyYWwgLSBTUkYxHDAaBgNVBAMTE0FDIENlcnRpU2lnbiBTUkYgVjMwHhcNMDYwNzE5MDAwMDAwWhcNMDkwNzE4MjM1OTU5WjCB1DELMAkGA1UEBhMCQlIxEzARBgNVBAoUCklDUC1CcmFzaWwxKjAoBgNVBAsTIVNlY3JldGFyaWEgZGEgUmVjZWl0YSBGZWRlcmFsLVNSRjETMBEGA1UECxQKU1JGIGUtQ05QSjELMAkGA1UECBMCUkoxFzAVBgNVBAcUDlJJTyBERSBKQU5FSVJPMUkwRwYDVQQDE0BUSVBMQU4gQ09OU1VMVE9SSUEgRSBTRVJWSUNPUyBFTSBJTkZPUk1BVElDQSBMVERBOjA0NjQyNTU0MDAwMTQzMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCx86LAoJRVmtQMzmtdWpyNgKy200+bwjtz/TuywNcTjvfw7qHFGIgTjipmuZ3zhX28CgYLYXp3tj1Dfh2B7EhjHdLJPfvoF4MgbN/dQGXmGpMpF5cNxYusOGCZiyASvI7Gqt/xE4xLSIalNr6kF6CaPLkpFgTNNe+WQkG0fMqsQQIDAQABo4ICCDCCAgQwgbEGA1UdEQSBqTCBpqA/BgVgTAEDBKA2DDQyNDA3MTk3NjA3MTM4NTM3Nzg2MDAwMDAwMDAwMDAwMDAwMDAwOTI5OTA2MjFDTkggIFJKoB8GBWBMAQMCoBYMFEZFUk5BTkRPIFNJTFZBIEJSQUdBoBkGBWBMAQMDoBAMDjA0NjQyNTU0MDAwMTQzoBEGBWBMAQMHoAgMBjIzOTU0OIEUZmJyYWdhQHRpcGxhbi5jb20uYnIwCQYDVR0TBAIwADBiBgNVHR8EWzBZMFegVaBThlFodHRwOi8vaWNwLWJyYXNpbC5jZXJ0aXNpZ24uY29tLmJyL3JlcG9zaXRvcmlvL2xjci9BQ0NlcnRpU2lnblNSRlYzL0xhdGVzdENSTC5jcmwwHwYDVR0jBBgwFoAU9p1ZXf6/xXLN3c7ELmYbLu4Iz3YwDgYDVR0PAQH/BAQDAgXgMFUGA1UdIAROMEwwSgYGYEwBAgMGMEAwPgYIKwYBBQUHAgEWMmh0dHA6Ly9pY3AtYnJhc2lsLmNlcnRpc2lnbi5jb20uYnIvcmVwb3NpdG9yaW8vZHBjMB0GA1UdJQQWMBQGCCsGAQUFBwMEBggrBgEFBQcDAjA4BggrBgEFBQcBAQQsMCowKAYIKwYBBQUHMAGGHGh0dHA6Ly9vY3NwLmNlcnRpc2lnbi5jb20uYnIwDQYJKoZIhvcNAQEFBQADggEBAC5w/CBXAykvPSbBGf+u0UPcWVJATL2ix0hCfNUVtHaCjMz8hRjgYqmhpefzDm2LCTvoCPzG6XQBYxAmnDhX1f/gyjHz+E1xJg451qtqcyCJ9861o9R2bHd4zR0DuyxCNGOTiYJ4Gc/Xa4xqECorAx5ktkk1T/HOc1K/ntRGpdL+llsO/jqSRmTOnRgdeNHcKkyXsOgL5BwxxgGNuIyqirgGXW0by4Io1GnSXtixxfvEOnqOicxBY6AcVS9HHuhmOBYiK9skAUp0Sm2v41hpsC8uIkfUeRxsJIp2CNZ4DjoyfmKwNLMCRZQAKpwMXyyHZlX1a4o/9iGTszNeeShw61g=</X509Certificate>
  </X509Data>
</KeyInfo>
</Signature>
</PedidoEnvioLoteRPS>

Below is the program I made to sign the legal note of Porto Alegre:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;

namespace escolhercertificadosimples
{
    public static class DocumentExtensions
    {
        public static XmlDocument ToXmlDocument(this XDocument xDocument)
        {
            var xmlDocument = new XmlDocument();
            using (var xmlReader = xDocument.CreateReader())
            {
                xmlDocument.Load(xmlReader);
            }
            return xmlDocument;
        }

        public static XDocument ToXDocument(this XmlDocument xmlDocument)
        {
            using (var nodeReader = new XmlNodeReader(xmlDocument))
            {
                nodeReader.MoveToContent();
                return XDocument.Load(nodeReader);
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            //Abre o deposito de certificados da maquina local
            var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            //var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadOnly);
            //Abre a tela de escolher certificado
            var selectedCertificate = X509Certificate2UI.SelectFromCollection(
                store.Certificates,
                "Title",
                "MSG",
                X509SelectionFlag.SingleSelection);

            //Pega o objeto x509 do certificado selecionado
            foreach (X509Certificate2 x509 in selectedCertificate)
            {
                try
                {
                    //Imprime informações do certificado, se existirem
                    byte[] rawdata = x509.RawData;
                    //Console.WriteLine("Content Type: {0}{1}", X509Certificate2.GetCertContentType(rawdata), Environment.NewLine);
                    //Console.WriteLine("Friendly Name: {0}{1}", x509.FriendlyName, Environment.NewLine);
                    //Console.WriteLine("Certificate Verified?: {0}{1}", x509.Verify(), Environment.NewLine);
                    //Console.WriteLine("Simple Name: {0}{1}", x509.GetNameInfo(X509NameType.SimpleName, true), Environment.NewLine);
                    //Console.WriteLine("Signature Algorithm: {0}{1}", x509.SignatureAlgorithm.FriendlyName, Environment.NewLine);
                    //Console.WriteLine("Private Key: {0}{1}", x509.PrivateKey.ToXmlString(false), Environment.NewLine);
                    //Console.WriteLine("Public Key: {0}{1}", x509.PublicKey.Key.ToXmlString(false), Environment.NewLine);
                    //Console.WriteLine("Certificate Archived?: {0}{1}", x509.Archived, Environment.NewLine);
                    //Console.WriteLine("Length of Raw Data: {0}{1}", x509.RawData.Length, Environment.NewLine);
                    //X509Certificate2UI.DisplayCertificate(x509);
                    //x509.Reset();


                    //==============================
                    // Comeca a ler os arquivos xml
                    //==============================
                    var txtFiles = Directory.EnumerateFiles("./", "*.xml");
                    //Console.WriteLine(txtFiles.Count());break;
                    foreach (string currentFile in txtFiles)
                    {

                        Console.WriteLine("Lendo o arquivo" + currentFile + ":");

                        var originalDoc = XDocument.Load(currentFile);

                        //string id = xe4.FirstAttribute.Value.ToString();
                        //Console.WriteLine(id);
                        //Console.WriteLine(xe4.ToString());


                        XmlDocument doc = DocumentExtensions.ToXmlDocument(originalDoc);

                        //====================================
                        // Comeca a Criacao da pasta Assinados
                        //====================================
                        // Specify the directory you want to manipulate.
                        string path_originais = "Originais";

                        try
                        {
                            // Determine whether the directory exists.
                            if (Directory.Exists(path_originais))
                            {
                                //Console.WriteLine("That path exists already.");
                                //Console.WriteLine("Pasta Assinados já existe.");
                                //return;
                            }
                            else
                            {

                                // Try to create the directory.
                                DirectoryInfo di = Directory.CreateDirectory(path_originais);
                                Console.WriteLine("The directory was created successfully at {0}.", Directory.GetCreationTime(path_originais));
                            }
                            // Delete the directory.
                            //di.Delete();
                            //Console.WriteLine("The directory was deleted successfully.");
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("The process failed: {0}", e.ToString());
                        }
                        finally { }

                        //doc.Save(path + "/teste.xml"); //break;

                        //Salva o novo arquivo assinado na pasta Assinados
                        doc.Save(path_originais + "/" + currentFile.Replace("./", "")); //break;






                        //==============================
                        // Comeca a Leitura das Notas
                        //==============================
                        XmlNodeList ListInfRps = doc.GetElementsByTagName("RPS");
                        //Console.WriteLine(ListInfRps.Count); break;


                        //Console.WriteLine("Aqui");

                        //Console.WriteLine(ListInfNFe);

                        //SignedXml signedXml = new SignedXml(doc);

                        //Console.WriteLine(ListInfRps.Count);

                        int NodeCounter = 1;

                        foreach (XmlElement InfRps in ListInfRps)
                        {
                            Console.Write("Assinando Nota " + NodeCounter + "...") ;
                            //Console.WriteLine(InfRps.InnerXml);
                            //continue;

                            //Console.WriteLine(InfRps.Value);

                            //string id = InfRps.Attributes.GetNamedItem("Id").Value;
                            //Console.WriteLine(id);
                            string id = "lote";

                            SignedXml signedXml = new SignedXml(InfRps);

                            signedXml.SigningKey = x509.PrivateKey;
                            //RSACryptoServiceProvider privateKey = x509.PrivateKey as RSACryptoServiceProvider;

                            // Transformações p/ DigestValue da Nota
                            //Reference reference = new Reference("#" + id);
                            Reference reference = new Reference("#" + id.Replace(":",""));
                            //Console.WriteLine("#" + id.Replace(":", ""));
                            //Reference reference = new Reference("#" + "lote");

                            reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());

                            reference.AddTransform(new XmlDsigC14NTransform());

                            signedXml.AddReference(reference);



                            KeyInfo keyInfo = new KeyInfo();
                            keyInfo.AddClause(new KeyInfoX509Data(x509));
                            signedXml.KeyInfo = keyInfo;



                            signedXml.ComputeSignature();



                            XmlElement xmlSignature = doc.CreateElement("Signature", "http://www.w3.org/2000/09/xmldsig#");

                            XmlAttribute attr = doc.CreateAttribute("Id");
                            attr.Value = "Ass_" + id;

                            //Add the attribute to the node     
                            xmlSignature.Attributes.SetNamedItem(attr);

                            XmlElement xmlSignedInfo = signedXml.SignedInfo.GetXml();
                            XmlElement xmlKeyInfo = signedXml.KeyInfo.GetXml();



                            XmlElement xmlSignatureValue = doc.CreateElement("SignatureValue", xmlSignature.NamespaceURI);
                            string signBase64 = Convert.ToBase64String(signedXml.Signature.SignatureValue);
                            XmlText text = doc.CreateTextNode(signBase64);
                            xmlSignatureValue.AppendChild(text);
                            //xmlSignature.AppendChild(xmlSignatureValue);



                            xmlSignature.AppendChild(doc.ImportNode(xmlSignedInfo, true));

                            xmlSignature.AppendChild(xmlSignatureValue);

                            xmlSignature.AppendChild(doc.ImportNode(xmlKeyInfo, true));


                            //InfRps.AppendChild(xmlSignature);

                            XmlNodeList ListRps = doc.GetElementsByTagName("Rps");
                            //Console.WriteLine(ListInfRps.Count); break;


                            //Console.WriteLine("Aqui");

                            //Console.WriteLine(ListInfNFe);

                            //SignedXml signedXml = new SignedXml(doc);

                            int RpsCounter = 1;

                            foreach (XmlElement Rps in ListRps)
                            {

                                //Console.WriteLine(Rps.InnerXml); return;
                                //Console.WriteLine(RpsCounter);
                                //Console.WriteLine(NodeCounter);

                                if (RpsCounter == NodeCounter)
                                {
                                    Rps.AppendChild(xmlSignature);
                                }
                                RpsCounter++;
                            }

                            Console.WriteLine("Ok");
                            NodeCounter++;
                        }





                        //==============================
                        // Comeca a Leitura do Lote
                        //==============================
                        XmlNodeList ListLoteRps = doc.GetElementsByTagName("PedidoEnvioLoteRPS");
                        //Console.WriteLine(ListInfRps.Count); break;


                        //Console.WriteLine("Aqui");

                        //Console.WriteLine(ListInfNFe);

                        //SignedXml signedXml = new SignedXml(doc);

                        foreach (XmlElement LoteRps in ListLoteRps)
                        {
                            Console.Write("Assinando Lote...");

                            //Console.WriteLine("Aquiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
                            //Console.WriteLine(InfRps.InnerXml);
                            //continue;

                            //Console.WriteLine(InfRps.Value);

                            string id = LoteRps.Attributes.GetNamedItem("Id").Value;
                            //Console.WriteLine(id);

                            SignedXml signedXml = new SignedXml(LoteRps);
                            //Console.WriteLine("1");
                            signedXml.SigningKey = x509.PrivateKey;
                            //RSACryptoServiceProvider privateKey = x509.PrivateKey as RSACryptoServiceProvider;
                            //Console.WriteLine("2");
                            // Transformações p/ DigestValue da Nota
                            Reference reference = new Reference("#" + id);
                            //Reference reference = new Reference("#" + "lote");
                            //Console.WriteLine("3");
                            reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
                            //Console.WriteLine("4");
                            reference.AddTransform(new XmlDsigC14NTransform());
                            //Console.WriteLine("5");
                            signedXml.AddReference(reference);

                            //Console.WriteLine("6");

                            KeyInfo keyInfo = new KeyInfo();
                            keyInfo.AddClause(new KeyInfoX509Data(x509));
                            signedXml.KeyInfo = keyInfo;

                            //Console.WriteLine("7");

                            signedXml.ComputeSignature();

                            //Console.WriteLine("8");

                            XmlElement xmlSignature = doc.CreateElement("Signature", "http://www.w3.org/2000/09/xmldsig#");

                            XmlAttribute attr = doc.CreateAttribute("Id");
                            attr.Value = "Ass_"+id;

                            //Add the attribute to the node     
                            xmlSignature.Attributes.SetNamedItem(attr);

                            XmlElement xmlSignedInfo = signedXml.SignedInfo.GetXml();
                            XmlElement xmlKeyInfo = signedXml.KeyInfo.GetXml();

                            //Console.WriteLine("9");

                            XmlElement xmlSignatureValue = doc.CreateElement("SignatureValue", xmlSignature.NamespaceURI);


                            string signBase64 = Convert.ToBase64String(signedXml.Signature.SignatureValue);
                            XmlText text = doc.CreateTextNode(signBase64);
                            xmlSignatureValue.AppendChild(text);
                            //xmlSignature.AppendChild(xmlSignatureValue);

                            //Console.WriteLine("10");

                            xmlSignature.AppendChild(doc.ImportNode(xmlSignedInfo, true));

                            xmlSignature.AppendChild(xmlSignatureValue);

                            xmlSignature.AppendChild(doc.ImportNode(xmlKeyInfo, true));


                            //LoteRps.AppendChild(xmlSignature);

                            XmlNodeList ListEnviarLoteRpsEnvio = doc.GetElementsByTagName("EnviarLoteRpsEnvio");
                            //Console.WriteLine(ListInfRps.Count); break;


                            //Console.WriteLine("Aqui");

                            //Console.WriteLine(ListInfNFe);

                            //SignedXml signedXml = new SignedXml(doc);

                            foreach (XmlElement EnviarLoteRpsEnvio in ListEnviarLoteRpsEnvio)
                            {
                                EnviarLoteRpsEnvio.AppendChild(xmlSignature);
                            }


                            Console.WriteLine("Ok");

                            //Console.WriteLine(InfRps.InnerXml);


                            //XmlNode root = doc.DocumentElement;
                            //XmlNode myNode = root.SelectSingleNode("descendant::LoteRps");
                            //myNode.AppendChild(xmlSignature);


                            //====================================
                            // Comeca a Criacao da pasta Assinados
                            //====================================
                            // Specify the directory you want to manipulate.
                            string path = "Assinados";

                            try
                            {
                                // Determine whether the directory exists.
                                if (Directory.Exists(path))
                                {
                                    //Console.WriteLine("That path exists already.");
                                    //Console.WriteLine("Pasta Assinados já existe.");
                                    //return;
                                }
                                else
                                {

                                    // Try to create the directory.
                                    DirectoryInfo di = Directory.CreateDirectory(path);
                                    Console.WriteLine("The directory was created successfully at {0}.", Directory.GetCreationTime(path));
                                }
                                // Delete the directory.
                                //di.Delete();
                                //Console.WriteLine("The directory was deleted successfully.");
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("The process failed: {0}", e.ToString());
                            }
                            finally { }

                            //doc.Save(path + "/teste.xml"); //break;

                            //Salva o novo arquivo assinado na pasta Assinados
                            doc.Save(path + "/" + currentFile.Replace("./","")); //break;



                            //Console.WriteLine("11");

                            //Encoding enc = Encoding.UTF8;
                            //MemoryStream ms = new MemoryStream();
                            //XmlTextWriter writer = new XmlTextWriter(ms, enc);

                            //Console.WriteLine("12");

                            //writer.Formatting = Formatting.Indented;
                            //writer.Indentation = 2;
                            //writer.Namespaces = true;

                            //Console.WriteLine("13");

                            //doc.WriteTo(writer);
                            //writer.Flush();
                            //writer.Close();

                            //Console.WriteLine("Aquiiiiiiiiiiiiiiiiiiiii");
                            //Console.WriteLine(writer.Namespaces);






                            //XmlWriterSettings oSettings = new XmlWriterSettings();
                            //oSettings.Indent = true;
                            //oSettings.OmitXmlDeclaration = false;
                            //oSettings.Encoding = Encoding.ASCII;

                            //XmlWriter writer1 = XmlWriter.Create("xmlfile.xml", oSettings);
                            //System.Xml.XmlElement xml = InfRps;
                            //xml.WriteContentTo(writer1);



                            //signedXml = new SignedXml(infNFe);
                            //signedXml.SigningKey = ObtemCertificado().PrivateKey;
                        }

                        //signedXml.SigningKey = x509.PrivateKey;
                        //signedXml.SignatureMethod;

                        //Console.WriteLine(signedXml.SignatureMethod);
                        //Console.WriteLine(signedXml.Signature);
                        //break;
                    }
                }
                catch (CryptographicException ce)
                {
                    Console.WriteLine(ce.ToString());
                    Console.WriteLine("Information could not be written out for this certificate.");
                }
            }
        }
    }
}

1 answer

0


I had the same problem.

To solve just pass the blank ID.

By default the URI in the Ference comes NULL just pass string.Empty and all is right.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.