CipherData Class
Assembly: System.Security (in system.security.dll)
The CipherData class represents the <CipherData> element in XML encryption. It is a required element that provides the encrypted data. It must either contain the encrypted data as base64-encoded text of the <CipherValue> element, or provide a reference to an external location containing the encrypted data using the <CipherReference> element.
In many cases, you do not need to directly create a new instance of the CipherData class. The EncryptedXml, EncryptedData, and EncryptedKey classes create instances for you.
Note |
|---|
| A CipherData object can have either a CipherReference property or a CipherValue property, but not both. A CryptographicException is thrown if both are assigned to a CipherData object. |
The following code example uses the EncryptedData class to create an <EncryptedData> element that contains a <CipherData> element, and then writes the XML to an XML file.
Imports System Imports System.Security.Cryptography.Xml Imports System.Xml Imports System.IO '/ This sample used the EncryptedData class to create a EncryptedData element '/ and write it to an XML file. Module EncryptedDataSample1 Sub Main() ' Create a new CipherData object. Dim cd As New CipherData ' Assign a byte array to the CipherValue. cd.CipherValue = New Byte(7) {} ' Create a new EncryptedData object. Dim ed As 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. Dim ki As 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. Dim doc As New XmlDocument Dim encryptionPropertyElement As XmlElement = CType(doc.CreateElement("EncryptionProperty", EncryptedXml.XmlEncNamespaceUrl), XmlElement) Dim ep As New EncryptionProperty(encryptionPropertyElement) ed.AddProperty(ep) ' Output the resulting XML information into a file. Dim path As String = "c:\test\MyTest.xml" File.WriteAllText(path, ed.GetXml().OuterXml) 'End Sub 'Main 'Console.WriteLine(ed.GetXml().OuterXml); End Sub End Module
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Note