using System;
using System.Security.Cryptography.Xml;
using System.Xml;
using System.IO;
class Sample1
{
[STAThread]
static void Main(string[] args)
{
String uri = "http://www.yourdomain.com/document.xml";
Transform base64 = new XmlDsigBase64Transform();
TransformChain tc = new TransformChain();
tc.Add(base64);
CipherReference reference = new CipherReference(uri, tc);
CipherData cd = new CipherData(reference);
EncryptedData ed = new EncryptedData();
ed.Id = "ED";
ed.EncryptionMethod = new EncryptionMethod("http://www.w3.org/2001/04/xmlenc#aes128-cbc");
ed.CipherData = cd;
KeyInfo ki = new KeyInfo();
ki.AddClause(new KeyInfoRetrievalMethod("#EK", "http://www.w3.org/2001/04/xmlenc#EncryptedKey"));
ed.KeyInfo = ki;
XmlDocument doc = new XmlDocument();
XmlElement encryptionPropertyElement = (XmlElement)doc.CreateElement("EncryptionProperty", EncryptedXml.XmlEncNamespaceUrl);
EncryptionProperty ep = new EncryptionProperty(encryptionPropertyElement);
ed.AddProperty(ep);
try{
string path = @"c:\MyTest.xml";
File.WriteAllText(path, ed.GetXml().OuterXml);
}
catch (IOException e)
{
Console.WriteLine("File IO error. {0}", e);
}
}
}