title: How do we read and attach a X509 certificate to Xml Digital Signature?
body: <p>I would like to read x509 certificate from TrustedPeople store and attach it to an XML document.</p>
  
  <pre><code>            RSAKeyValue rsaKey = new RSAKeyValue();
              XmlDocument xmlDoc = new XmlDocument();
              string filename = "C:/Documents and Settings/sbtho/Desktop/downloads/samp.xml";
              string filename1 = "C:/Documents and Settings/sbtho/Desktop/downloads/sampdigsig.xml";
              xmlDoc.PreserveWhitespace = false;
              xmlDoc.Load(new XmlTextReader(filename));
  
              SignedXml signedXml = new SignedXml(xmlDoc);
              signedXml.SigningKey = rsaKey.Key;
              Signature xmlSignature = signedXml.Signature;
  
              Reference reference = new Reference("");
              XmlDsigEnvelopedSignatureTransform envelope = new XmlDsigEnvelopedSignatureTransform();
              XmlDsigC14NWithCommentsTransform envelope1 = new XmlDsigC14NWithCommentsTransform();
              reference.AddTransform(envelope);
              reference.AddTransform(envelope1);
              xmlSignature.SignedInfo.AddReference(reference);
  
              KeyInfo keyInfo = new KeyInfo();
               X509Store store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser);
              store.Open(OpenFlags.ReadOnly);
              X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindByThumbprint, "ffa8ebf4760ab2d145b8ca21b1de258923e7d9d8", false);
              store.Close();
              keyInfo.AddClause(rsaKey);
              xmlSignature.KeyInfo = keyInfo;
              signedXml.ComputeSignature();
  
              XmlElement xmlDigSign = signedXml.GetXml();
              xmlDoc.DocumentElement.AppendChild(xmlDoc.ImportNode(xmlDigSign, true));
  
              if (xmlDoc.FirstChild.GetType() == typeof(XmlDeclaration))
                  xmlDoc.RemoveChild(xmlDoc.FirstChild);
  
              XmlTextWriter xmlWriter = new XmlTextWriter(filename1, new UTF8Encoding(false));
              xmlDoc.WriteTo(xmlWriter);
              xmlWriter.Close();
  </code></pre>
  
  <p>This is how far I reached.Its reading from the trustedpeople store. How can I now insert this certificate into the XML document?</p>