DataObject Class
Represents the object element of an XML signature that holds data to be signed.
Assembly: System.Security (in System.Security.dll)
| Name | Description | |
|---|---|---|
![]() | 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. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | GetXml() | Returns the XML representation of the DataObject object. |
![]() | LoadXml(XmlElement^) | Loads a DataObject state from an XML element. |
![]() | MemberwiseClone() | |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
Use the DataObject class to store information or metadata directly in an XML signature. For example, you can store the signature generation date or the signer's identity. The DataObject class may or may not be covered by the XML signature.
The class corresponds to the <Object> element in the World Wide Web Consortium (W3C) specification for XML Signatures. For more information about the W3C specification, see http://www.w3.org/TR/xmldsig-core/.
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" ); } }
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


