title: C# XML Encryption X509 Certificate (XmlElement Content Only)
body: <p>I would like to encrypt the content of an XmlElement using an X509 Certificate.</p>
  <p>Microsoft has provided an example here: <a href="https://docs.microsoft.com/en-us/dotnet/standard/security/how-to-encrypt-xml-elements-with-x-509-certificates" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/dotnet/standard/security/how-to-encrypt-xml-elements-with-x-509-certificates</a></p>
  <p>The &quot;Encrypt&quot; method takes two parameters (XmlElement and X509 Certificate) and it works great. But the method encrypts the entire XmlElement. I want to encrypt only the content of the XmlElement.</p>
  <p>There's another method called &quot;EncryptData&quot; which takes a third parameter (boolean) allowing to specify whether only the content should be encrypted. Unfortunately, this method returns a byte array and does not simply take an X509 certificate in its parameters.</p>
  <p>Is there any way to use the simple &quot;Encrypt&quot; method to encrypt only the content of the XmlElement?</p>
  <p>Any other possibilities to solve this in a simple way?</p>