本文整理匯總了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);
}
}
}