本文整理汇总了C#中System.Security.Cryptography.Xml.CipherData类的典型用法代码示例。如果您正苦于以下问题:C# CipherData类的具体用法?C# CipherData怎么用?C# CipherData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CipherData类属于System.Security.Cryptography.Xml命名空间,在下文中一共展示了CipherData类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Security.Cryptography.Xml;
using System.Xml;
using System.IO;
/// This sample used the EncryptedData class to create a EncryptedData element
/// and write it to an XML file.
namespace EncryptedDataSample
{
class Sample1
{
[STAThread]
static void Main(string[] args)
{
// Create a new CipherData object.
CipherData cd = new CipherData();
// Assign a byte array to be the CipherValue. This is a byte array representing encrypted data.
cd.CipherValue = new byte[8];
// Create a new EncryptedData object.
EncryptedData ed = new EncryptedData();
//Add an encryption method to the object.
ed.Id = "ED";
ed.EncryptionMethod = new EncryptionMethod("http://www.w3.org/2001/04/xmlenc#aes128-cbc");
ed.CipherData = cd;
//Add key information to the object.
KeyInfo ki = new KeyInfo();
ki.AddClause(new KeyInfoRetrievalMethod("#EK", "http://www.w3.org/2001/04/xmlenc#EncryptedKey"));
ed.KeyInfo = ki;
// Create new XML document and put encrypted data into it.
XmlDocument doc = new XmlDocument();
XmlElement encryptionPropertyElement = (XmlElement)doc.CreateElement("EncryptionProperty", EncryptedXml.XmlEncNamespaceUrl);
EncryptionProperty ep = new EncryptionProperty(encryptionPropertyElement);
ed.AddProperty(ep);
// Output the resulting XML information into a file.
string path = @"c:\test\MyTest.xml";
File.WriteAllText(path,ed.GetXml().OuterXml);
//Console.WriteLine(ed.GetXml().OuterXml);
}
}
}