SignedXml.AddObject(DataObject) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
서명할 개체 목록에 DataObject 개체를 추가합니다.
public:
void AddObject(System::Security::Cryptography::Xml::DataObject ^ dataObject);
public void AddObject(System.Security.Cryptography.Xml.DataObject dataObject);
member this.AddObject : System.Security.Cryptography.Xml.DataObject -> unit
Public Sub AddObject (dataObject As DataObject)
매개 변수
- dataObject
- DataObject
서명할 개체 목록에 추가할 DataObject 개체입니다.
예제
다음 코드 예제에서는 계산 및 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)
{
try
{
// 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.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 the reference 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();
Console.WriteLine("The data was signed.");
}
catch(CryptographicException e)
{
Console.WriteLine(e.Message);
}
}
}
Imports System.IO
Imports System.Security.Cryptography
Imports System.Security.Cryptography.Xml
Imports System.Xml
Public Class XMLdsigsample1
Overloads Shared Sub Main(args() As [String])
Try
' 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.WriteLine(("Data to sign:" + ControlChars.Lf + document.OuterXml + ControlChars.Lf))
' 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 the reference 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()
Console.WriteLine("The data was signed.")
Catch e As CryptographicException
Console.WriteLine(e.Message)
End Try
End Sub
End Class
설명
메서드는 AddObject XML 디지털 서명의 요소에 서명할 개체를 <Signature>
나타내는 요소를 추가 <Object>
합니다.
메서드는 AddObject 내부적으로 호출 합니다 AddObject 개체에 Signature 의해 캡슐화 된 개체의 SignedXml 메서드입니다. 속성에서 Signature 메서드를 DataObject 직접 호출하여 개체를 AddObject 추가할 수도 있습니다.
XML 디지털 서명에 대한 자세한 내용은 XMLDSIG 사양을 참조하세요.