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.
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.
– heringer
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”" 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 "”". It’s the only thing that’s different.
– James Braz
this "″" there is the quote code. The post on the link is wrong, it was wrong. You can start this.
– heringer
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.
– heringer
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.
– James Braz
@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.
– Muriel Souza