DataObject::Data Property

 

Gets or sets the data value of the current DataObject object.

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

public:
property XmlNodeList^ Data {
	XmlNodeList^ get();
	void set(XmlNodeList^ value);
}

Property Value

Type: System.Xml::XmlNodeList^

The data of the current DataObject.

Exception Condition
System::ArgumentNullException

The value used to set the property is null.

This property is the XML node list that contains the element described in the Id property.

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

#using <System.dll>
#using <System.Xml.dll>
#using <System.Security.dll>

using namespace System;
using namespace System::IO;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::Xml;
using namespace System::Xml;
int main()
{

   // Create example data to sign.
   XmlDocument^ document = gcnew 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{0}\n", document->OuterXml );

   // Create the SignedXml message.
   SignedXml^ signedXml = gcnew SignedXml;
   RSA^ key = RSA::Create();
   signedXml->SigningKey = key;

   // Create a data object to hold the data to sign.
   DataObject^ dataObject = gcnew 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 = gcnew Reference;
   reference->Uri = "#MyObjectId";

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

   // Add a KeyInfo.
   KeyInfo^ keyInfo = gcnew KeyInfo;
   keyInfo->AddClause( gcnew 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.

#using <System.dll>
#using <System.Security.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::Xml;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   array<String^>^args = System::Environment::GetCommandLineArgs();
   Console::WriteLine( "Verifying {0}...", args[ 1 ] );

   // Create a SignedXml.
   SignedXml^ signedXml = gcnew SignedXml;

   // Load the XML.
   XmlDocument^ xmlDocument = gcnew XmlDocument;
   xmlDocument->PreserveWhitespace = true;
   xmlDocument->Load( gcnew XmlTextReader( args[ 1 ] ) );
   XmlNodeList^ nodeList = xmlDocument->GetElementsByTagName( "Signature" );
   signedXml->LoadXml( safe_cast<XmlElement^>(nodeList[ 0 ]) );
   if ( signedXml->CheckSignature() )
   {
      Console::WriteLine( "Signature check OK" );
   }
   else
   {
      Console::WriteLine( "Signature check FAILED" );
   }
}

.NET Framework
Available since 1.1
Return to top
Show: