Op Englesch liesen Editéieren

Deelen iwwer


CipherData Constructors

Definition

Initializes a new instance of the CipherData class.

Overloads

CipherData()

Initializes a new instance of the CipherData class.

CipherData(Byte[])

Initializes a new instance of the CipherData class using a byte array as the CipherValue value.

CipherData(CipherReference)

Initializes a new instance of the CipherData class using a CipherReference object.

CipherData()

Source:
CipherData.cs
Source:
CipherData.cs
Source:
CipherData.cs
Source:
CipherData.cs
Source:
CipherData.cs
Source:
CipherData.cs

Initializes a new instance of the CipherData class.

C#
public CipherData();

Examples

The following code example shows how to create a new instance of the CipherData class. The entire sample can be found in the CipherData class topic.

C#
// 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];

Remarks

This constructor creates a CipherData object that represents the <CipherData> element in XML encryption. The <CipherData> element is a required element in XML encryption.

Applies to

.NET 10 (package-provided) an aner Versiounen
Produkt Versiounen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

CipherData(Byte[])

Source:
CipherData.cs
Source:
CipherData.cs
Source:
CipherData.cs
Source:
CipherData.cs
Source:
CipherData.cs
Source:
CipherData.cs

Initializes a new instance of the CipherData class using a byte array as the CipherValue value.

C#
public CipherData(byte[] cipherValue);

Parameters

cipherValue
Byte[]

The encrypted data to use for the <CipherValue> element.

Exceptions

The cipherValue parameter is null.

The CipherValue property has already been set.

Examples

The following code example shows how to create a new instance of the CipherData class.

C#
// Create a new CipherData object using a byte array to represent encrypted data.
Byte[] sampledata = new byte[8];
CipherData cd = new CipherData(sampledata);

Remarks

This constructor creates a CipherData object that represents the <CipherData> element in XML encryption. The constructor assigns the cipherValue value to the CipherValue property as the actual encrypted data.

Notiz

The <CipherData> element can have either a CipherReference or a CipherValue child element, but not both. A CryptographicException is thrown if both are assigned to a CipherData object.

Applies to

.NET 10 (package-provided) an aner Versiounen
Produkt Versiounen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

CipherData(CipherReference)

Source:
CipherData.cs
Source:
CipherData.cs
Source:
CipherData.cs
Source:
CipherData.cs
Source:
CipherData.cs
Source:
CipherData.cs

Initializes a new instance of the CipherData class using a CipherReference object.

C#
public CipherData(System.Security.Cryptography.Xml.CipherReference cipherReference);

Parameters

cipherReference
CipherReference

The CipherReference object to use.

Exceptions

The cipherValue parameter is null.

The CipherValue property has already been set.

Examples

The following code example shows how to create a new instance of the CipherData class using CipherReference information.

C#
using System;
using System.Security.Cryptography.Xml;
using System.Xml;
using System.IO;

/// This sample used the EncryptedData class to create an encrypted data element
/// and write it to an XML file. It demonstrates the use of CipherReference.
namespace EncryptedDataSample
{
    class Example
    {
        [STAThread]
        static void Main(string[] args)
        {
            //Create a URI string.
            String uri = "http://www.woodgrovebank.com/document.xml";
            // Create a Base64 transform. The input content retrieved from the
            // URI should be Base64-decoded before other processing.
            Transform base64 = new XmlDsigBase64Transform();
            //Create a transform chain and add the transform to it.
            TransformChain tc = new TransformChain();
            tc.Add(base64);
            //Create <CipherReference> information.
            CipherReference reference = new CipherReference(uri, tc);

            // Create a new CipherData object using the CipherReference information.
            // Note that you cannot assign both a CipherReference and a CipherValue
            // to a CipherData object.
            CipherData cd = new CipherData(reference);

            // 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.
            try
            {
                string path = @"c:\test\MyTest.xml";

                File.WriteAllText(path, ed.GetXml().OuterXml);
            }
            catch (IOException e)
            {
                Console.WriteLine("File IO error. {0}", e);
            }
        }
    }
}

Remarks

This constructor creates a CipherData object that represents the <CipherData> element in XML encryption and assigns the cipherReference value to the CipherReference property. The CipherReference object represents the <CipherReference> element, which provides the location of the encrypted data.

Notiz

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.

Applies to

.NET 10 (package-provided) an aner Versiounen
Produkt Versiounen
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10