DataObject Constructors

Definition

Initializes a new instance of the DataObject class.

Overloads

DataObject()

Initializes a new instance of the DataObject class.

DataObject(String, String, String, XmlElement)

Initializes a new instance of the DataObject class with the specified identification, MIME type, encoding, and data.

DataObject()

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

Initializes a new instance of the DataObject class.

C#
public DataObject();

Examples

The following code example demonstrates how to generate an enveloping XML signature.

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

public class XMLdsigsample1 {

static void Main(String[] args)
{
     // Create example data to sign.
     XmlDocument document = new XmlDocument();
     XmlNode  node = document.CreateNode(XmlNodeType.Element, "", "MyElement", "samples");
     node.InnerText = "This is some text";
     document.AppendChild(node);
     Console.Error.WriteLine("Data to sign:\n" + document.OuterXml + "\n");

     // Create the SignedXml message.
     SignedXml signedXml = new SignedXml();
     RSA key = RSA.Create();
     signedXml.SigningKey = key;

     // Create a data object to hold the data to sign.
     DataObject dataObject = new DataObject();
     dataObject.Data = document.ChildNodes;
     dataObject.Id = "MyObjectId";

     // Add the data object to the signature.
     signedXml.AddObject(dataObject);

     // Create a reference to be able to package everything into the
     // message.
     Reference reference = new Reference();
     reference.Uri = "#MyObjectId";

     // Add it to the message.
     signedXml.AddReference(reference);

     // Add a KeyInfo.
     KeyInfo keyInfo = new KeyInfo();
     keyInfo.AddClause(new RSAKeyValue(key));
     signedXml.KeyInfo = keyInfo;

     // Compute the signature.
     signedXml.ComputeSignature();

     // Get the XML representation of the signature.
     XmlElement xmlSignature = signedXml.GetXml();
     Console.WriteLine(xmlSignature.OuterXml);
}
}

The following code example demonstrates how to check an XML signature.

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

public class Verify {

    public static void Main(String[] args)
    {

        Console.WriteLine("Verifying " + args[0] + "...");

        // Create a SignedXml.
        SignedXml signedXml = new SignedXml();

        // Load the XML.
        XmlDocument xmlDocument = new XmlDocument();
        xmlDocument.PreserveWhitespace = true;
        xmlDocument.Load(new XmlTextReader(args[0]));

        XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");
        signedXml.LoadXml((XmlElement)nodeList[0]);

        if (signedXml.CheckSignature()) {
            Console.WriteLine("Signature check OK");
        } else {
            Console.WriteLine("Signature check FAILED");
        }
    }
}

Remarks

The DataObject class is used with XML signatures. After you have initialized the DataObject, you can assign the Data and Id properties.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 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

DataObject(String, String, String, XmlElement)

Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs
Source:
DataObject.cs

Initializes a new instance of the DataObject class with the specified identification, MIME type, encoding, and data.

C#
public DataObject(string id, string mimeType, string encoding, System.Xml.XmlElement data);

Parameters

id
String

The identification to initialize the new instance of DataObject with.

mimeType
String

The MIME type of the data used to initialize the new instance of DataObject.

encoding
String

The encoding of the data used to initialize the new instance of DataObject.

data
XmlElement

The data to initialize the new instance of DataObject with.

Exceptions

The data parameter is null.

Remarks

The DataObject class is used with XML signatures. The id parameter refers to the name of the element that contains the data to be used. The data parameter refers to the XML node list that contains the id parameter element.

Applies to

.NET 10 (package-provided) and other versions
Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 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