private XmlElement siganatureXML(XmlDocument doc, Parametros parametro) { if (doc == null) { throw new ArgumentException("xmlDoc"); } var xmlDocumentSignature = new XmlDocument(); SignatureXML signatureXML = new SignatureXML(); XmlElement Signature = signatureXML.XmlElement(xmlDocumentSignature); //SignedInfo SignedInfoXMl SignedInfoXMl = new SignedInfoXMl(); XmlElement SignedInfoxml = SignedInfoXMl.XmlElement(xmlDocumentSignature); CanonicalizationMethodXML CanonicalizationMethodXML = new CanonicalizationMethodXML(); XmlElement CanonicalizationMethodxml = CanonicalizationMethodXML.XmlElement(xmlDocumentSignature); CanonicalizationMethodXML.XMlAttributeAlgorithm(CanonicalizationMethodxml); SignatureMethodXML SignatureMethodXML = new SignatureMethodXML(); XmlElement SignatureMethodxml = SignatureMethodXML.XmlElement(xmlDocumentSignature); SignatureMethodXML.XMlAttributeAlgorithm(SignatureMethodxml); ReferenceXML ReferenceXML = new ReferenceXML(); XmlElement Referencexml = ReferenceXML.XmlElement(xmlDocumentSignature); ReferenceXML.XMlAttributeURI(Referencexml); TransformsXML TransformsXML = new TransformsXML(); XmlElement Transformsxml = TransformsXML.XmlElement(xmlDocumentSignature); TransformXML TransformXML = new TransformXML(); XmlElement Transformxml = TransformXML.XmlElement(xmlDocumentSignature); TransformXML.XMlAttributeAlgorithm(Transformxml); Transformsxml.AppendChild(Transformxml); Referencexml.AppendChild(Transformsxml); string digest = DigestUtils.CreateDigest(doc.OuterXml); DigestMethodXML DigestMethodXML = new DigestMethodXML(); XmlElement DigestMethodxml = DigestMethodXML.XmlElement(xmlDocumentSignature); DigestMethodXML.XMlAttributeAlgorithm(DigestMethodxml); Referencexml.AppendChild(DigestMethodxml); DigestValueXML DigestValueXML = new DigestValueXML(); XmlElement DigestValuexml = DigestValueXML.XmlElement(xmlDocumentSignature);; DigestValuexml.InnerText = digest; Referencexml.AppendChild(DigestValuexml); SignedInfoxml.AppendChild(CanonicalizationMethodxml); SignedInfoxml.AppendChild(SignatureMethodxml); SignedInfoxml.AppendChild(Referencexml); //SignedInfo string signature = DigestUtils.Sign(SignedInfoxml.OuterXml, parametro.certificado.getX509Certificate2()); //SignatureValue SignatureValueXML SignatureValueXML = new SignatureValueXML(); XmlElement SignatureValuexml = SignatureValueXML.XmlElement(xmlDocumentSignature); SignatureValuexml.InnerText = signature; //SignatureValue //KeyInfo KeyInfoXML KeyInfoXML = new KeyInfoXML(); XmlElement KeyInfoXMl = KeyInfoXML.XmlElement(xmlDocumentSignature); X509DataXML X509Data = new X509DataXML(); XmlElement X509DataXML = X509Data.XmlElement(xmlDocumentSignature); X509IssuerSerialXML X509IssuerSerialXML = new X509IssuerSerialXML(); XmlElement x5019Issuer = X509IssuerSerialXML.XmlElement(xmlDocumentSignature); X509IssuerNameXML X509IssuerNameXML = new X509IssuerNameXML(); XmlElement X509IssuerName = X509IssuerNameXML.XmlElement(xmlDocumentSignature); X509IssuerName.InnerText = parametro.certificado.getX509Certificate2().IssuerName.Name; x5019Issuer.AppendChild(X509IssuerName); X509SerialNumberXML X509SerialNumberXML = new X509SerialNumberXML(); XmlElement X509SerialNumber = X509SerialNumberXML.XmlElement(xmlDocumentSignature); X509SerialNumber.InnerText = parametro.certificado.getX509Certificate2().GetSerialNumberString(); x5019Issuer.AppendChild(X509SerialNumber); X509DataXML.AppendChild(x5019Issuer); X509CertificateXML X509Certificate = new X509CertificateXML(); XmlElement X509CertificateXML = X509Certificate.XmlElement(xmlDocumentSignature); X509CertificateXML.InnerText = DigestUtils.convertToBase64X509Certificate(parametro.certificado.getX509Certificate2()); X509DataXML.AppendChild(X509CertificateXML); KeyInfoXMl.AppendChild(X509DataXML); //KeyInfo Signature.AppendChild(SignedInfoxml); Signature.AppendChild(SignatureValuexml); Signature.AppendChild(KeyInfoXMl); xmlDocumentSignature.AppendChild(Signature); return(Signature); }