WebService Sefaz Error 297 Recipient's Manifestation

0

I am developing a module of manifestation of the recipient next to the Sefaz. When sending with the Xml already signed I have the following return error: <cStat>297</cStat><xMotivo>Rejeicao: Assinatura difere do calculado</xMotivo> .

I have already listened to some suggestions in some forums where it is recommended to observe some escapes and special characters within the XML elements.

The signature of the XML file is validated without problems on the site of the ministry of the farm ( link ).

Can anyone help me with what might be happening?

The using XML for submission is as follows:

<?xml version="1.0" encoding="utf-8"?>
<envEvento xmlns="http://www.portalfiscal.inf.br/nfe" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" versao="1.00">
<idLote>1</idLote>
<evento versao="1.00">
<infEvento Id="ID2102103518064328381100910655001000067942126336601001">
  <cOrgao>91</cOrgao>
  <tpAmb>1</tpAmb>
  <CNPJ>53773073000182</CNPJ>
  <chNFe>35180643283811009106550010000679421263366010</chNFe>
  <dhEvento>2018-07-25T02:47:06-03:00</dhEvento>
  <tpEvento>210210</tpEvento>
  <nSeqEvento>1</nSeqEvento>
  <verEvento>1.00</verEvento>
  <detEvento versao="1.00">
    <descEvento>Ciencia da Operacao</descEvento>
  </detEvento>
</infEvento>
<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="#ID2102103518064328381100910655001000067942126336601001">
      <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>BahmhJGVCbcRzzZ2a3IdfoGggSY=</DigestValue>
    </Reference>
  </SignedInfo>
  <SignatureValue>01MRXk7YiSo9g8OBqR0H4gmYxXBHCFAfoloKacDOYMZ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GVyZXphQHNvZnRpbmcuY29tLmJyoDgGBWBMAQMEoC8ELTIxMTAxOTUyODc0ODY0MzE4MTUwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMKAUBgVgTAEDAqALBAlUSU5HIFlBTkegGQYFYEwBAwOgEAQONTM3NzMwNzMwMDAxODKgFwYFYEwBAwegDgQMMDAwMDAwMDAwMDAwMA0GCSqGSIb3DQEBCwUAA4ICAQAz9zGz3gT09rIOmkKTF1ZnRt2oGeedEnlqrJ7lqV9vu3xjyzEQoFyqmp2u93YeMuTOi7hjeZ0BYaPnNJbOlJ2I4sJwioJc/PsAqn+VDbb7KVrUC6VXZVYs/9tsFETrNdal7BnGXts5wiZtPa1iRx90RLxFfJeJ0E2Y/0kY4VCagn+vovgyYB76i8F03lkJnW2ScpCeaunva2NurlORRiNfhy9YpBqYdIZA5I0S3qOlgi1BLdrNkNHnlAsv7VO3xzEwsX/pR8g7b97TYtjcxJpnz3zeCLJb2Fawudd6C2aubUUxotbj7W/ER1De8yDDHKd7xt62s8Qarw2EICBMQzaGKKnQXBzddtCmS1Skjbloq5s03dH2Q0NJigG7lodRrSWvndtTkmoksL/IjOVq6z4sBYB36mPr+PqMklnisU6pinHa5/vFbJiIfbbNHdcogp+ndOz9AMRS76EtJubspQ/sSALZzicp1bXtgpnaLdOC+ow8pW1XH/bZOcWDo1vieQCs7Y/T2tPIEw4FBa6BvEwbK4w31VUaoe3aac/Wlhl52f7aydp/4VeH5fzFk2sTMpOw5a8tGyO5Avoem1SCJEinjJBLBu9V3UF/4kJc7M4+8i8MdX50cJA30Go5EpMnuvB4nHe8x9RxgpFyBhoqRWkTLBvHCs84OPlu6jMN0whE2Q==</X509Certificate>
    </X509Data>
  </KeyInfo>
</Signature>
</evento>
<evento versao="1.00">
<infEvento Id="ID2102103518064328381100910655001000067986126343904601">
  <cOrgao>91</cOrgao>
  <tpAmb>1</tpAmb>
  <CNPJ>53773073000182</CNPJ>
  <chNFe>35180643283811009106550010000679861263439046</chNFe>
  <dhEvento>2018-07-25T02:47:06-03:00</dhEvento>
  <tpEvento>210210</tpEvento>
  <nSeqEvento>1</nSeqEvento>
  <verEvento>1.00</verEvento>
  <detEvento versao="1.00">
    <descEvento>Ciencia da Operacao</descEvento>
  </detEvento>
</infEvento>
<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="#ID2102103518064328381100910655001000067986126343904601">
      <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>atbTWNxi44DcxulttJidbuNCxQo=</DigestValue>
    </Reference>
  </SignedInfo>
  <SignatureValue>+wxGkr1l7uFnzlcPFhOSnMN675j9syXlPW9L2UupO1lAienG0GQ9Ta786Wh3/RmqLywfhjob6KXXkh2iiVXAUrOVcQU9akRxwlse93auCEJRff5uQChgKryQycu6XigB/nhNPE50ay8xnhFsSR3nHGYjWcWVnKi6uQAnM69Bx6lOQpvTTh+pSNM2/lXD/eC94b3iKzEi4DkE0yfQ1LRUGd7tUnB0/Y8j+Hu+w8pFYh6Nurabmv1GjNRzpDooZUGxcuWkvtVsFd3VshVqIZ7FKIMnGw8fcsN2h+sv3/OQqe7MJ78z98fMoUv/R1FTklWYqV6vUptK1XnyJ61VbHz1XQ==</SignatureValue>
  <KeyInfo>
    <X509Data>
      <X509Certificate>MIIH6TCCBdGgAwIBAgIIDsPfGUgZG6UwDQYJKoZIhvcNAQELBQAwcTELMAkGA1UEBhMCQlIxEzARBgNVBAoTCklDUC1CcmFzaWwxNjA0BgNVBAsTLVNlY3JldGFyaWEgZGEgUmVjZWl0YSBGZWRlcmFsI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X/pR8g7b97TYtjcxJpnz3zeCLJb2Fawudd6C2aubUUxotbj7W/ER1De8yDDHKd7xt62s8Qarw2EICBMQzaGKKnQXBzddtCmS1Skjbloq5s03dH2Q0NJigG7lodRrSWvndtTkmoksL/IjOVq6z4sBYB36mPr+PqMklnisU6pinHa5/vFbJiIfbbNHdcogp+ndOz9AMRS76EtJubspQ/sSALZzicp1bXtgpnaLdOC+ow8pW1XH/bZOcWDo1vieQCs7Y/T2tPIEw4FBa6BvEwbK4w31VUaoe3aac/Wlhl52f7aydp/4VeH5fzFk2sTMpOw5a8tGyO5Avoem1SCJEinjJBLBu9V3UF/4kJc7M4+8i8MdX50cJA30Go5EpMnuvB4nHe8x9RxgpFyBhoqRWkTLBvHCs84OPlu6jMN0whE2Q==</X509Certificate>
    </X509Data>
  </KeyInfo>
</Signature>
</evento>
</envEvento>

The portion of the XML signature is as follows:

public XmlDocument retornaEvtsXMLAssinados(X509Certificate2 cert, string MensagemXML)
{            
    XmlDocument xmlDoc = new XmlDocument();

    xmlDoc.LoadXml(MensagemXML);
    XmlNodeList evtsNode = xmlDoc.GetElementsByTagName("infEvento");

    foreach (XmlElement evtNode in evtsNode)
    {
        RSACryptoServiceProvider key = new System.Security.Cryptography.RSACryptoServiceProvider();
        System.Security.Cryptography.Xml.SignedXml SignedDocument;
        KeyInfo keyInfo = new KeyInfo();
        keyInfo.AddClause(new KeyInfoX509Data(cert));
        key = (System.Security.Cryptography.RSACryptoServiceProvider)cert.PrivateKey;
        SignedDocument = new System.Security.Cryptography.Xml.SignedXml(evtNode);
        SignedDocument.SigningKey = key;
        SignedDocument.KeyInfo = keyInfo;
        Reference reference = new System.Security.Cryptography.Xml.Reference();
        reference.Uri = "#" + evtNode.Attributes["Id"].Value;
        reference.AddTransform(new XmlDsigEnvelopedSignatureTransform());
        reference.AddTransform(new XmlDsigC14NTransform(false));
        SignedDocument.AddReference(reference);
        SignedDocument.ComputeSignature();
        XmlElement xmlDigitalSignature = SignedDocument.GetXml();
        XmlNode nodeAss = xmlDoc.ImportNode(xmlDigitalSignature, true);
        evtNode.ParentNode.AppendChild(nodeAss);
    }

    return xmlDoc;
}

Thank you.

    
asked by anonymous 25.07.2018 / 21:03

0 answers