I show this code since with this code I currently generate my digital signature, what I want is to add to my signature the NameSpace
to SignedInfo
so that it looks like this:
SignedInfo xmlns="http://www.w3.org/2000/09/xmldsig#" xsi: schemaLocation="http://www.sii.cl/SiiDte EnvioDTE_v10.xsd"
This is my code and even though I see it, I do not know how to insert it ... maybe with replace
?
public static XmlDocument FirmarDocumento(XmlDocument xmldocumentD, X509Certificate2 certificadoD, string referenciaUriD)
{
// Create a SignedXml object.
SignedXml signedXml = new SignedXml(xmldocumentD);
// Add the key to the SignedXml document.
signedXml.SigningKey = certificadoD.PrivateKey;
Signature XMLSignature = signedXml.Signature;
// Create a reference to be signed.
Reference reference = new Reference();
reference.Uri = "#" + referenciaUriD;
// Add an enveloped transformation to the reference.
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
// Add the reference to the SignedXml object.
XMLSignature.SignedInfo.AddReference(reference);
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new RSAKeyValue((RSA)certificadoD.PrivateKey));
////
//// Agregar información del certificado x509
keyInfo.AddClause(new KeyInfoX509Data(certificadoD));
XMLSignature.KeyInfo = keyInfo;
// Compute the signature.
signedXml.ComputeSignature();
// Get the XML representation of the signature and save
// it to an XmlElement object.
XmlElement xmlDigitalSignature = signedXml.GetXml();
// Append the element to the XML document.
xmldocumentD.DocumentElement.AppendChild(xmldocumentD.ImportNode(xmlDigitalSignature, true));
return xmldocumentD;
}