REINF - Invalid Signature

1

I'm developing a messaging for reinf but I'm having trouble sending the first event. By sending a R1000 I'm getting the message:

MS0017

Invalid event signature. Digital signature of XML document is invalid

I am generating the event xml using the XmlSerializer class. First I download the xsd files from reinf, I pass them to xsd.exe to generate the classes in C #, I generate an event object, I populate the properties and then serialize as below:

XmlSerializer ArquivoSerializer = new XmlSerializer(typeof(T));
using (FileStream ArquivoStream = new FileStream(pObjArquivo.FullName, FileMode.CreateNew))
{
  using (XmlWriter ArquivoWriter = XmlWriter.Create(ArquivoStream))
  {
    ArquivoSerializer.Serialize(ArquivoWriter, pSerializableObject);
  }
  return new FileInfo(ArquivoStream.Name);
}

So far so good. Then the manual asks us to send the event in the form of enveloped lots. Creating the batches xml in the same way did not work. Reinf rejects the generated file from your batch send xsd, so I've booted an alternative:

XNamespace ns = "http://www.reinf.esocial.gov.br/schemas/envioLoteEventos/v1_01_01";

XDocument eventoAssinado = XDocument.Load(pFileEventoAssinado.FullName);

XDocument doc = new XDocument(
            new XElement(ns + "Reinf",
                         new XAttribute("xmlns", ns.NamespaceName),
                         new XAttribute(XNamespace.Xmlns + "xsd", "http://www.w3.org/2001/XMLSchema"),
                         new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
                         new XElement(ns + "loteEventos",
                            new XElement(ns + "evento",
                                         new XAttribute("id", pFileEventoAssinado.Name.Replace(".xml", string.Empty)),
                                         new XElement(eventoAssinado.Root)
                                        ))
                         ));

This xml yes is processed by reinf, but returning the error of the beginning of the question. The question is: Is it that when I'm adding the Root of my event to the new xml this causes some change in the signed event itself, invalidating my signature? Can anyone recommend me a better practice than this one?

I use the same signing method in eSocial without any problems.

    
asked by anonymous 24.10.2017 / 14:06

1 answer

2

James, a difference between eSocial and EFD-Reinf, until the last time I tested Reinf (I'm more development-oriented for eSocial) was that in Reinf it was necessary to report "#IdDoEvent" in the URI element of the signature , whereas the URI element in eSocial must be empty.

I also did something similar to what you did, I used the XSD.exe tool to create objects from the XSDs made available by the government, but, by answering your question, I also used the object generated from XSD to manipulate the batch upload, something like:

 lote.envioLoteEventos.eventos.evento[iCount] = new EnvioLoteEventos.TArquivoEsocial();
 lote.envioLoteEventos.eventos.evento[iCount].Id = idEvento;
 // Serializa o objeto para um documento XML e o assina.
 var eventoAssinado = SerializaEAssina(evento, certificado);
 // Adiciona o XML assinado do evento ao array de eventos do lote.
 lote.envioLoteEventos.eventos.evento[iCount].Any = eventoAssinado.DocumentElement;

I have an XML example that was successfully sent to EFD-Reinf at the time I tested: link

    
20.02.2018 / 05:32