Id Property
Collapse the table of content
Expand the table of content

DataObject.Id Property


Gets or sets the identification of the current DataObject object.

Namespace:   System.Security.Cryptography.Xml
Assembly:  System.Security (in System.Security.dll)

public string Id { get; set; }

Property Value

Type: System.String

The name of the element that contains data to be used.

The identification is used to reference the DataObject from another location. The default value of this property is null, which implies that no identification is present. This property is commonly referenced by the SignedInfo property.

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

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";
     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.

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

     // Add it to the message.

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

     // Compute the signature.

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


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

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");

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


.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft