DataObject.Id プロパティとは? わかりやすく解説

DataObject.Id プロパティ

現在の DataObject オブジェクトID取得または設定します

名前空間: System.Security.Cryptography.Xml
アセンブリ: System.Security (system.security.dll 内)
構文構文

解説解説

ID は、別の場所から DataObject参照するために使用されます。このプロパティ既定値null 参照 (Visual Basic では Nothing) です。これは、ID存在しないことを意味します。このプロパティは、通常 SignedInfo プロパティ参照されます。

使用例使用例

エンベロープXML 署名生成する方法次のコード例示します

Imports System
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 'Main
End Class 'XMLdsigsample1 
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);
}

}
#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 );
}

import System.*;
import System.IO.*;
import System.Security.Cryptography.*;
import System.Security.Cryptography.Xml.*;
import System.Xml.*;

public class XmlDsigSample1
{
    public static void main(String[]
 args)
    {
        // Create example data to sign.
        XmlDocument document = new XmlDocument();
        XmlNode node = document.CreateNode(XmlNodeType.Element, "",
            "MyElement", "samples");
        node.set_InnerText("This is some text");
        document.AppendChild(node);
        Console.get_Error().WriteLine("Data to sign:\n" +
            document.get_OuterXml() + "\n");
        // Create the SignedXml message.
        SignedXml signedXml = new SignedXml();
        RSA key = RSA.Create();
        signedXml.set_SigningKey(key);
        // Create a data object to hold the data to sign.
        DataObject dataObject = new DataObject();
        dataObject.set_Data(document.get_ChildNodes());
        dataObject.set_Id("MyObjectId");
        // Add the data object to the signature.
        signedXml.AddObject(dataObject);
        // Create a reference to be able to
        Reference reference = new Reference();
        reference.set_Uri("#MyObjectId");
        // Add it to the message.
        signedXml.AddReference(reference);
        // Add a KeyInfo.
        KeyInfo keyInfo = new KeyInfo();
        keyInfo.AddClause(new RSAKeyValue(key));
        signedXml.set_KeyInfo(keyInfo);
        // Compute the signature.
        signedXml.ComputeSignature();
        // Get the XML representation of the signature.
        XmlElement xmlSignature = signedXml.GetXml();
        Console.WriteLine(xmlSignature.get_OuterXml());
    } //main
} //XmlDsigSample1 

XML 署名確認する方法次のコード例示します

Imports System
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 'Main 
End Class 'Verify
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");
        }

    }
}
#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" );
   }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataObject クラス
DataObject メンバ
System.Security.Cryptography.Xml 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DataObject.Id プロパティ」の関連用語

DataObject.Id プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataObject.Id プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS