REINF - Invalid Signature

Asked

Viewed 989 times

3

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

MS0017

Invalid event signature. Invalid XML document Digital signature

I am generating the event xml using the Xmlserializer class. First I download the xsd files from reinf, step them into xsd.exe to generate the classes in C#, Gero an event object, fill in the properties and then serializo 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 batches. Creating batch xml didn’t work anyway. Reinf rejects the file generated from its batch submission xsd, so I’ve come up with 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 returns the error at the beginning of the question. The question is: Does when I am adding the root of my eventAssing the new xml generate some change in the signed event itself, invalidating my signature? Can anyone recommend me a better practice than this?

I use the same signature method in eSocial without problems.

  • 1

    I had this problem because the text was not UTF-8. Try to force the UTF-8 encoding. Take a look at this link also.

  • Thanks for the @Heringer ! reply I tried using UTF-8 in the file signature, xml generation and batch and it didn’t work. Reinf keeps returning the same mistake. I could not use the signature method of the link you sent because when trying to sign the Signedxml method.Computesignature() with the Digestmethod = "http://www.w3.org/2001/04/xmlenc#sha256&#8221" I get an Exception saying that the hash algorithm could not be created. It only works when I use "http://www.w3.org/2001/04/xmlenc#sha256", without the "&#8221". It’s the only thing that’s different.

  • 1

    this "&#8243" there is the quote code. The post on the link is wrong, it was wrong. You can start this.

  • I don’t know if you’ve solved it yet, but if you still need it, I’ve provided an implementation with unit testing at this link. If you want to use, edit the constants of the Pseudotest class. One is the certificate serial number and the other is the CNPJ of the company that owns the certificate.

  • I managed to send this morning. I will post an answer detailing the problem and the solution for posterity rs. Your reply was critical to the @Heringer resolution, thank you very much.

  • @Jamesbraz, I looked that you managed to solve the problem of signing the event, you came to comment that would publish the reply detailing the resolution of the problem. I published a question recently, because I have the same problem, follow the question: Reinf Invalid Signature If you can contribute your detailed reply I thank you very much because I still have the problem, thank you.

Show 1 more comment

1 answer

3

James, a difference between eSocial and EFD-Reinf, until the last time I tested Reinf (I’m more focused on eSocial development) was that in Reinf it was necessary to inform "#Iddoevento" in the signature URI element, while the URI element in eSocial should be empty.

I also did something similar to what you did, I used the XSD.exe tool to create objects from the government-available Xsds, but, answering your question, I also used the object generated from XSD to manipulate the shipment batch, 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 example of XML that was successfully sent to EFD-Reinf at the time I tested: http://suporte.quarta.com.br/eSocial/arquivos/R1000_EnvioLote.xml

  • Why this answer is being denied if it gives a hint to answer the original question ("Invalid event signature" -> The event ID in the URI element must be informed) and even suggests a solution to a problem commented on in the original question ("Creating batch xml the same way didn’t work" -> Posted a code snippet that allows you to embed the signed event into the batch object without having to create batch XML by hand), and still has link to a valid EFD-Reinf batch example?

  • Pedro, an excellent answer, I voted in his reply, it was very valid to help me solve the problem. Don’t worry about negativity ignorance does these things.

Browser other questions tagged

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