DataObject 생성자

정의

DataObject 클래스의 새 인스턴스를 초기화합니다.

오버로드

Name Description
DataObject()

DataObject 클래스의 새 인스턴스를 초기화합니다.

DataObject(String, String, String, XmlElement)

지정된 ID, MIME 형식, 인코딩 및 데이터를 사용하여 클래스의 DataObject 새 인스턴스를 초기화합니다.

DataObject()

DataObject 클래스의 새 인스턴스를 초기화합니다.

public:
 DataObject();
public DataObject();
Public Sub New ()

예제

다음 코드 예제에서는 인벨로핑 XML 서명을 생성하는 방법을 보여 줍니다.

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);
}
}
Imports System.IO
Imports System.Security.Cryptography
Imports System.Security.Cryptography.Xml
Imports System.Xml

 _


Public Class XMLdsigsample1

   Shared Sub Main(args() As [String])
      ' Create example data to sign.
      Dim document As New XmlDocument()
      Dim node As XmlNode = document.CreateNode(XmlNodeType.Element, "", "MyElement", "samples")
      node.InnerText = "This is some text"
      document.AppendChild(node)
      Console.Error.WriteLine("Data to sign:")
      Console.Error.WriteLine()
      Console.Error.WriteLine(document.OuterXml)
      Console.Error.WriteLine()
      
      ' Create the SignedXml message.
      Dim signedXml As New SignedXml()
      Dim key As RSA = RSA.Create()
      signedXml.SigningKey = key
      
      ' Create a data object to hold the data to sign.
      Dim dataObject As 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.
      Dim reference As New Reference()
      reference.Uri = "#MyObjectId"
      
      ' Add it to the message.
      signedXml.AddReference(reference)
      
      ' Add a KeyInfo.
      Dim keyInfo As New KeyInfo()
      keyInfo.AddClause(New RSAKeyValue(key))
      signedXml.KeyInfo = keyInfo
      
      ' Compute the signature.
      signedXml.ComputeSignature()
      
      ' Get the XML representation of the signature.
      Dim xmlSignature As XmlElement = signedXml.GetXml()
      Console.WriteLine(xmlSignature.OuterXml)
   End Sub
End Class

다음 코드 예제에서는 XML 서명을 확인하는 방법을 보여 줍니다.

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");
        }
    }
}
Imports System.Security.Cryptography
Imports System.Security.Cryptography.Xml
Imports System.IO
Imports System.Xml

 _

Public Class Verify
   
   Public Shared Sub Main(args() As [String])
      
      Console.WriteLine(("Verifying " + args(0) + "..."))
      
      ' Create a SignedXml.
      Dim signedXml As New SignedXml()
      
      ' Load the XML.
      Dim xmlDocument As New XmlDocument()
      xmlDocument.PreserveWhitespace = True
      xmlDocument.Load(New XmlTextReader(args(0)))
      
      Dim nodeList As XmlNodeList = xmlDocument.GetElementsByTagName("Signature")
      signedXml.LoadXml(CType(nodeList(0), XmlElement))
      
      If signedXml.CheckSignature() Then
         Console.WriteLine("Signature check OK")
      Else
         Console.WriteLine("Signature check FAILED")
      End If
   End Sub
End Class

설명

DataObject 클래스는 XML 서명과 함께 사용됩니다. 초기화한 DataObject후에는 해당 속성과 Id 속성을 할당할 Data 수 있습니다.

적용 대상

DataObject(String, String, String, XmlElement)

지정된 ID, MIME 형식, 인코딩 및 데이터를 사용하여 클래스의 DataObject 새 인스턴스를 초기화합니다.

public:
 DataObject(System::String ^ id, System::String ^ mimeType, System::String ^ encoding, System::Xml::XmlElement ^ data);
public DataObject(string id, string mimeType, string encoding, System.Xml.XmlElement data);
new System.Security.Cryptography.Xml.DataObject : string * string * string * System.Xml.XmlElement -> System.Security.Cryptography.Xml.DataObject
Public Sub New (id As String, mimeType As String, encoding As String, data As XmlElement)

매개 변수

id
String

새 인스턴스를 초기화할 ID입니다 DataObject .

mimeType
String

새 인스턴스를 초기화하는 데 사용되는 데이터의 MIME 형식입니다 DataObject.

encoding
String

새 인스턴스를 초기화하는 데 사용되는 데이터의 인코딩입니다 DataObject.

data
XmlElement

새 인스턴스 DataObject 를 초기화할 데이터입니다.

예외

매개 변수는 data .입니다 null.

설명

DataObject 클래스는 XML 서명과 함께 사용됩니다. 매개 변수는 id 사용할 데이터가 포함된 요소의 이름을 나타냅니다. 매개 변수는 data 매개 변수 요소를 포함하는 XML 노드 목록을 참조합니다 id .

적용 대상