DataObject.Id 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 DataObject 개체의 ID를 가져오거나 설정합니다.
public:
property System::String ^ Id { System::String ^ get(); void set(System::String ^ value); };
public string? Id { get; set; }
public string Id { get; set; }
member this.Id : string with get, set
Public Property Id As String
속성 값
사용할 데이터가 들어 있는 요소의 이름입니다.
예제
다음 코드 예제에서는 인벨로핑 XML 서명을 생성하는 방법을 보여 줍니다.
#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 );
}
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.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" );
}
}
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
설명
ID는 다른 위치에서 를 DataObject 참조하는 데 사용됩니다. 이 속성의 기본값은 이며 null
, 이는 ID가 없음을 의미합니다. 이 속성은 일반적으로 참조 되는 속성입니다 SignedInfo .
적용 대상
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET