本文整理汇总了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);
}
}
}
开发者ID:.NET开发者,项目名称:System.Security.Cryptography.Xml,代码行数:44,代码来源:CipherData
注:本文中的System.Security.Cryptography.Xml.CipherData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论