SignedXml Klasa

Definicja

Udostępnia otokę podstawowego obiektu podpisu XML, aby ułatwić tworzenie podpisów XML.

public ref class SignedXml
public class SignedXml
type SignedXml = class
Public Class SignedXml
Dziedziczenie
SignedXml

Przykłady

Poniższy przykład kodu pokazuje, jak podpisać i zweryfikować cały dokument XML przy użyciu sygnatury kopertowej.

//
// This example signs an XML file using an
// envelope signature. It then verifies the 
// signed XML.
//
#using <System.Security.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::X509Certificates;
using namespace System::Security::Cryptography::Xml;
using namespace System::Text;
using namespace System::Xml;

// Sign an XML file and save the signature in a new file. This method does not  
// save the public key within the XML file.  This file cannot be verified unless  
// the verifying code has the key with which it was signed.
void SignXmlFile( String^ FileName, String^ SignedFileName, RSA^ Key )
{
   
   // Create a new XML document.
   XmlDocument^ doc = gcnew XmlDocument;
   
   // Load the passed XML file using its name.
   doc->Load( gcnew XmlTextReader( FileName ) );
   
   // Create a SignedXml object.
   SignedXml^ signedXml = gcnew SignedXml( doc );
   
   // Add the key to the SignedXml document. 
   signedXml->SigningKey = Key;
   
   // Create a reference to be signed.
   Reference^ reference = gcnew Reference;
   reference->Uri = "";
   
   // Add an enveloped transformation to the reference.
   XmlDsigEnvelopedSignatureTransform^ env = gcnew XmlDsigEnvelopedSignatureTransform;
   reference->AddTransform( env );
   
   // Add the reference to the SignedXml object.
   signedXml->AddReference( reference );
   
   // Compute the signature.
   signedXml->ComputeSignature();
   
   // Get the XML representation of the signature and save
   // it to an XmlElement object.
   XmlElement^ xmlDigitalSignature = signedXml->GetXml();
   
   // Append the element to the XML document.
   doc->DocumentElement->AppendChild( doc->ImportNode( xmlDigitalSignature, true ) );
   if ( (doc->FirstChild)->GetType() == XmlDeclaration::typeid )
   {
      doc->RemoveChild( doc->FirstChild );
   }

   
   // Save the signed XML document to a file specified
   // using the passed string.
   XmlTextWriter^ xmltw = gcnew XmlTextWriter( SignedFileName,gcnew UTF8Encoding( false ) );
   doc->WriteTo( xmltw );
   xmltw->Close();
}


// Verify the signature of an XML file against an asymmetric 
// algorithm and return the result.
Boolean VerifyXmlFile( String^ Name, RSA^ Key )
{
   
   // Create a new XML document.
   XmlDocument^ xmlDocument = gcnew XmlDocument;
   
   // Load the passed XML file into the document. 
   xmlDocument->Load( Name );
   
   // Create a new SignedXml object and pass it
   // the XML document class.
   SignedXml^ signedXml = gcnew SignedXml( xmlDocument );
   
   // Find the "Signature" node and create a new
   // XmlNodeList object.
   XmlNodeList^ nodeList = xmlDocument->GetElementsByTagName( "Signature" );
   
   // Load the signature node.
   signedXml->LoadXml( safe_cast<XmlElement^>(nodeList->Item( 0 )) );
   
   // Check the signature and return the result.
   return signedXml->CheckSignature( Key );
}


// Create example data to sign.
void CreateSomeXml( String^ FileName )
{
   
   // Create a new XmlDocument Object*.
   XmlDocument^ document = gcnew XmlDocument;
   
   // Create a new XmlNode object.
   XmlNode^ node = document->CreateNode( XmlNodeType::Element, "", "MyElement", "samples" );
   
   // Add some text to the node.
   node->InnerText = "Example text to be signed.";
   
   // Append the node to the document.
   document->AppendChild( node );
   
   // Save the XML document to the file name specified.
   XmlTextWriter^ xmltw = gcnew XmlTextWriter( FileName,gcnew UTF8Encoding( false ) );
   document->WriteTo( xmltw );
   xmltw->Close();
}

int main()
{
   try
   {
      
      // Generate a signing key.
      RSA^ Key = RSA::Create();
      
      // Create an XML file to sign.
      CreateSomeXml( "Example.xml" );
      Console::WriteLine( "New XML file created." );
      
      // Sign the XML that was just created and save it in a 
      // new file.
      SignXmlFile( "Example.xml", "signedExample.xml", Key );
      Console::WriteLine( "XML file signed." );
      
      // Verify the signature of the signed XML.
      Console::WriteLine( "Verifying signature..." );
      bool result = VerifyXmlFile( "SignedExample.xml", Key );
      
      // Display the results of the signature verification to 
      // the console.
      if ( result )
      {
         Console::WriteLine( "The XML signature is valid." );
      }
      else
      {
         Console::WriteLine( "The XML signature is not valid." );
      }
   }
   catch ( CryptographicException^ e ) 
   {
      Console::WriteLine( e->Message );
   }

}
//
// This example signs an XML file using an
// envelope signature. It then verifies the 
// signed XML.
//
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Xml;

public class SignVerifyEnvelope
{

    public static void Main(String[] args)
    {
        try
        {
           // Generate a signing key.
           RSA Key = RSA.Create();

           // Create an XML file to sign.
           CreateSomeXml("Example.xml");
           Console.WriteLine("New XML file created."); 

           // Sign the XML that was just created and save it in a 
           // new file.
           SignXmlFile("Example.xml", "signedExample.xml", Key);
           Console.WriteLine("XML file signed."); 

           // Verify the signature of the signed XML.
           Console.WriteLine("Verifying signature...");
           bool result = VerifyXmlFile("SignedExample.xml", Key);

           // Display the results of the signature verification to 
           // the console.
           if(result)
           {
               Console.WriteLine("The XML signature is valid.");
           }
           else
           {
            Console.WriteLine("The XML signature is not valid.");
           }
        }
        catch(CryptographicException e)
        {
            Console.WriteLine(e.Message);
        }
    }

    // Sign an XML file and save the signature in a new file. This method does not  
    // save the public key within the XML file.  This file cannot be verified unless  
    // the verifying code has the key with which it was signed.
    public static void SignXmlFile(string FileName, string SignedFileName, RSA Key)
    {
        // Create a new XML document.
        XmlDocument doc = new XmlDocument();

        // Load the passed XML file using its name.
        doc.Load(new XmlTextReader(FileName));

        // Create a SignedXml object.
        SignedXml signedXml = new SignedXml(doc);

        // Add the key to the SignedXml document. 
        signedXml.SigningKey = Key;

        // Create a reference to be signed.
        Reference reference = new Reference();
        reference.Uri = "";

        // Add an enveloped transformation to the reference.
        XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
        reference.AddTransform(env);

        // Add the reference to the SignedXml object.
        signedXml.AddReference(reference);

        // Compute the signature.
        signedXml.ComputeSignature();

        // Get the XML representation of the signature and save
        // it to an XmlElement object.
        XmlElement xmlDigitalSignature = signedXml.GetXml();

        // Append the element to the XML document.
        doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, true));
        
        if (doc.FirstChild is XmlDeclaration)  
        {
            doc.RemoveChild(doc.FirstChild);
        }

        // Save the signed XML document to a file specified
        // using the passed string.
        XmlTextWriter xmltw = new XmlTextWriter(SignedFileName, new UTF8Encoding(false));
        doc.WriteTo(xmltw);
        xmltw.Close();
    }

    // Verify the signature of an XML file against an asymmetric 
    // algorithm and return the result.
    public static Boolean VerifyXmlFile(String Name, RSA Key)
    {
        // Create a new XML document.
        XmlDocument xmlDocument = new XmlDocument();

        // Load the passed XML file into the document. 
        xmlDocument.Load(Name);

        // Create a new SignedXml object and pass it
        // the XML document class.
        SignedXml signedXml = new SignedXml(xmlDocument);

        // Find the "Signature" node and create a new
        // XmlNodeList object.
        XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");

        // Load the signature node.
        signedXml.LoadXml((XmlElement)nodeList[0]);

        // Check the signature and return the result.
        return signedXml.CheckSignature(Key);
    }

    // Create example data to sign.
    public static void CreateSomeXml(string FileName)
    {
        // Create a new XmlDocument object.
        XmlDocument document = new XmlDocument();

        // Create a new XmlNode object.
        XmlNode  node = document.CreateNode(XmlNodeType.Element, "", "MyElement", "samples");
        
        // Add some text to the node.
        node.InnerText = "Example text to be signed.";

        // Append the node to the document.
        document.AppendChild(node);

        // Save the XML document to the file name specified.
        XmlTextWriter xmltw = new XmlTextWriter(FileName, new UTF8Encoding(false));
        document.WriteTo(xmltw);
        xmltw.Close();
    }
}
'
' This example signs an XML file using an
' envelope signature. It then verifies the 
' signed XML.
'
Imports System.Security.Cryptography
Imports System.Security.Cryptography.X509Certificates
Imports System.Security.Cryptography.Xml
Imports System.Text
Imports System.Xml



Public Class SignVerifyEnvelope
   
   Overloads Public Shared Sub Main(args() As [String])
      Try
         ' Generate a signing key.
         Dim Key As RSA = RSA.Create()
         
         ' Create an XML file to sign.
         CreateSomeXml("Example.xml")
         Console.WriteLine("New XML file created.")
         
         ' Sign the XML that was just created and save it in a 
         ' new file.
         SignXmlFile("Example.xml", "signedExample.xml", Key)
         Console.WriteLine("XML file signed.")
         
         ' Verify the signature of the signed XML.
         Console.WriteLine("Verifying signature...")
         Dim result As Boolean = VerifyXmlFile("SignedExample.xml", Key)
         
         ' Display the results of the signature verification to 
         ' the console.
         If result Then
            Console.WriteLine("The XML signature is valid.")
         Else
            Console.WriteLine("The XML signature is not valid.")
         End If
      Catch e As CryptographicException
         Console.WriteLine(e.Message)
      End Try
   End Sub 
   
   
   
   ' Sign an XML file and save the signature in a new file. This method does not  
   ' save the public key within the XML file.  This file cannot be verified unless  
   ' the verifying code has the key with which it was signed.
   Public Shared Sub SignXmlFile(FileName As String, SignedFileName As String, Key As RSA)
      ' Create a new XML document.
      Dim doc As New XmlDocument()
      
      ' Load the passed XML file using its name.
      doc.Load(New XmlTextReader(FileName))
      
      ' Create a SignedXml object.
      Dim signedXml As New SignedXml(doc)
      
      ' Add the key to the SignedXml document. 
      signedXml.SigningKey = Key
      
      ' Create a reference to be signed.
      Dim reference As New Reference()
      reference.Uri = ""
      
      ' Add an enveloped transformation to the reference.
      Dim env As New XmlDsigEnvelopedSignatureTransform()
      reference.AddTransform(env)
      
      ' Add the reference to the SignedXml object.
      signedXml.AddReference(reference)
      
      ' Compute the signature.
      signedXml.ComputeSignature()
      
      ' Get the XML representation of the signature and save
      ' it to an XmlElement object.
      Dim xmlDigitalSignature As XmlElement = signedXml.GetXml()
      
      ' Append the element to the XML document.
      doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, True))
      
      If TypeOf doc.FirstChild Is XmlDeclaration Then
         doc.RemoveChild(doc.FirstChild)
      End If
      
      ' Save the signed XML document to a file specified
      ' using the passed string.
      Dim xmltw As New XmlTextWriter(SignedFileName, New UTF8Encoding(False))
      doc.WriteTo(xmltw)
      xmltw.Close()
   End Sub
   
   
   ' Verify the signature of an XML file against an asymmetric 
   ' algorithm and return the result.
   Public Shared Function VerifyXmlFile(Name As [String], Key As RSA) As [Boolean]
      ' Create a new XML document.
      Dim xmlDocument As New XmlDocument()
      
      ' Load the passed XML file into the document. 
      xmlDocument.Load(Name)
      
      ' Create a new SignedXml object and pass it
      ' the XML document class.
      Dim signedXml As New SignedXml(xmlDocument)
      
      ' Find the "Signature" node and create a new
      ' XmlNodeList object.
      Dim nodeList As XmlNodeList = xmlDocument.GetElementsByTagName("Signature")
      
      ' Load the signature node.
      signedXml.LoadXml(CType(nodeList(0), XmlElement))
      
      ' Check the signature and return the result.
      Return signedXml.CheckSignature(Key)
   End Function 
   
   
   
   ' Create example data to sign.
   Public Shared Sub CreateSomeXml(FileName As String)
      ' Create a new XmlDocument object.
      Dim document As New XmlDocument()
      
      ' Create a new XmlNode object.
      Dim node As XmlNode = document.CreateNode(XmlNodeType.Element, "", "MyElement", "samples")
      
      ' Add some text to the node.
      node.InnerText = "Example text to be signed."
      
      ' Append the node to the document.
      document.AppendChild(node)
      
      ' Save the XML document to the file name specified.
      Dim xmltw As New XmlTextWriter(FileName, New UTF8Encoding(False))
      document.WriteTo(xmltw)
      xmltw.Close()
   End Sub 
End Class

W poniższym przykładzie kodu pokazano, jak podpisać i zweryfikować pojedynczy element dokumentu XML przy użyciu podpisu otaczającego.

//
// This example signs an XML file using an
// envelope signature. It then verifies the 
// signed XML.
//
#using <System.Xml.dll>
#using <System.Security.dll>
#using <System.dll>

using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::Xml;
using namespace System::Text;
using namespace System::Xml;

// Sign an XML file and save the signature in a new file.
static void SignXmlFile( String^ FileName, String^ SignedFileName, RSA^ Key, array<String^>^ElementsToSign )
{
   
   // Check the arguments.  
   if ( FileName == nullptr )
      throw gcnew ArgumentNullException( L"FileName" );

   if ( SignedFileName == nullptr )
      throw gcnew ArgumentNullException( L"SignedFileName" );

   if ( Key == nullptr )
      throw gcnew ArgumentNullException( L"Key" );

   if ( ElementsToSign == nullptr )
      throw gcnew ArgumentNullException( L"ElementsToSign" );

   
   // Create a new XML document.
   XmlDocument^ doc = gcnew XmlDocument;
   
   // Format the document to ignore white spaces.
   doc->PreserveWhitespace = false;
   
   // Load the passed XML file using it's name.
   doc->Load( gcnew XmlTextReader( FileName ) );
   
   // Create a SignedXml object.
   SignedXml^ signedXml = gcnew SignedXml( doc );
   
   // Add the key to the SignedXml document. 
   signedXml->SigningKey = Key;
   
   // Loop through each passed element to sign 
   // and create a reference.
   System::Collections::IEnumerator^ myEnum = ElementsToSign->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      String^ s = safe_cast<String^>(myEnum->Current);
      
      // Create a reference to be signed.
      Reference^ reference = gcnew Reference;
      reference->Uri = s;
      
      // Add an enveloped transformation to the reference.
      XmlDsigEnvelopedSignatureTransform^ env = gcnew XmlDsigEnvelopedSignatureTransform;
      reference->AddTransform( env );
      
      // Add the reference to the SignedXml object.
      signedXml->AddReference( reference );
   }

   
   // Add an RSAKeyValue KeyInfo (optional; helps recipient find key to validate).
   KeyInfo^ keyInfo = gcnew KeyInfo;
   keyInfo->AddClause( gcnew RSAKeyValue( dynamic_cast<RSA^>(Key) ) );
   signedXml->KeyInfo = keyInfo;
   
   // Compute the signature.
   signedXml->ComputeSignature();
   
   // Get the XML representation of the signature and save
   // it to an XmlElement object.
   XmlElement^ xmlDigitalSignature = signedXml->GetXml();
   
   // Append the element to the XML document.
   doc->DocumentElement->AppendChild( doc->ImportNode( xmlDigitalSignature, true ) );
   if ( dynamic_cast<XmlDeclaration^>(doc->FirstChild) )
   {
      doc->RemoveChild( doc->FirstChild );
   }

   
   // Save the signed XML document to a file specified
   // using the passed string.
   XmlTextWriter^ xmltw = gcnew XmlTextWriter( SignedFileName,gcnew UTF8Encoding( false ) );
   doc->WriteTo( xmltw );
   xmltw->Close();
}


// Verify the signature of an XML file and return the result.
static Boolean VerifyXmlFile( String^ Name )
{
   
   // Check the arguments.  
   if ( Name == nullptr )
      throw gcnew ArgumentNullException( L"Name" );

   
   // Create a new XML document.
   XmlDocument^ xmlDocument = gcnew XmlDocument;
   
   // Format using white spaces.
   xmlDocument->PreserveWhitespace = true;
   
   // Load the passed XML file into the document. 
   xmlDocument->Load( Name );
   
   // Create a new SignedXml object and pass it
   // the XML document class.
   SignedXml^ signedXml = gcnew SignedXml( xmlDocument );
   
   // Find the "Signature" node and create a new
   // XmlNodeList object.
   XmlNodeList^ nodeList = xmlDocument->GetElementsByTagName( L"Signature" );
   
   // Load the signature node.
   signedXml->LoadXml( dynamic_cast<XmlElement^>(nodeList->Item( 0 )) );
   
   // Check the signature and return the result.
   return signedXml->CheckSignature();
}

int main()
{
   
   // Generate a signing key.
   RSA^ Key = RSA::Create();
   try
   {
      
      // Specify an element to sign. 
      array<String^>^elements = {L"#tag1"};
      
      // Sign an XML file and save the signature to a 
      // new file.
      SignXmlFile( L"Test.xml", L"SignedExample.xml", Key, elements );
      Console::WriteLine( L"XML file signed." );
      
      // Verify the signature of the signed XML.
      Console::WriteLine( L"Verifying signature..." );
      bool result = VerifyXmlFile( L"SignedExample.xml" );
      
      // Display the results of the signature verification to 
      // the console.
      if ( result )
      {
         Console::WriteLine( L"The XML signature is valid." );
      }
      else
      {
         Console::WriteLine( L"The XML signature is not valid." );
      }
   }
   catch ( CryptographicException^ e ) 
   {
      Console::WriteLine( e->Message );
   }
   finally
   {
      
      // Clear resources associated with the 
      // RSA instance.
      Key->Clear();
   }

   return 1;
}
//
// This example signs an XML file using an
// envelope signature. It then verifies the
// signed XML.
//
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Xml;

public class SignVerifyEnvelope
{

    public static void Main(String[] args)
    {
        // Generate a signing key.
       RSA Key = RSA.Create();

       try
       {
           // Specify an element to sign.
           string[] elements =  { "#tag1" };

           // Sign an XML file and save the signature to a
           // new file.
           SignXmlFile("Test.xml", "SignedExample.xml", Key, elements);
           Console.WriteLine("XML file signed.");

           // Verify the signature of the signed XML.
           Console.WriteLine("Verifying signature...");

           bool result = VerifyXmlFile("SignedExample.xml");

           // Display the results of the signature verification to
           // the console.
           if (result)
           {
               Console.WriteLine("The XML signature is valid.");
           }
           else
           {
               Console.WriteLine("The XML signature is not valid.");
           }
       }
       catch (CryptographicException e)
       {
           Console.WriteLine(e.Message);
       }
       finally
       {
           // Clear resources associated with the
           // RSA instance.
           Key.Clear();
       }
   }

    // Sign an XML file and save the signature in a new file.
    public static void SignXmlFile(string FileName, string SignedFileName, RSA Key, string[] ElementsToSign)
    {
        // Check the arguments.
        if (FileName == null)
            throw new ArgumentNullException("FileName");
        if (SignedFileName == null)
            throw new ArgumentNullException("SignedFileName");
        if (Key == null)
            throw new ArgumentNullException("Key");
        if (ElementsToSign == null)
            throw new ArgumentNullException("ElementsToSign");

        // Create a new XML document.
        XmlDocument doc = new XmlDocument();

        // Format the document to ignore white spaces.
        doc.PreserveWhitespace = false;

        // Load the passed XML file using it's name.
        doc.Load(new XmlTextReader(FileName));

        // Create a SignedXml object.
        SignedXml signedXml = new SignedXml(doc);

        // Add the key to the SignedXml document.
        signedXml.SigningKey = Key;

        // Loop through each passed element to sign
        // and create a reference.
        foreach (string s in ElementsToSign)
        {
            // Create a reference to be signed.
            Reference reference = new Reference();
            reference.Uri = s;

            // Add an enveloped transformation to the reference.
            XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
            reference.AddTransform(env);

            // Add the reference to the SignedXml object.
            signedXml.AddReference(reference);
        }

        // Add an RSAKeyValue KeyInfo (optional; helps recipient find key to validate).
        KeyInfo keyInfo = new KeyInfo();
        keyInfo.AddClause(new RSAKeyValue((RSA)Key));
        signedXml.KeyInfo = keyInfo;

        // Compute the signature.
        signedXml.ComputeSignature();

        // Get the XML representation of the signature and save
        // it to an XmlElement object.
        XmlElement xmlDigitalSignature = signedXml.GetXml();

        // Append the element to the XML document.
        doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, true));

        if (doc.FirstChild is XmlDeclaration)
        {
            doc.RemoveChild(doc.FirstChild);
        }

        // Save the signed XML document to a file specified
        // using the passed string.
        XmlTextWriter xmltw = new XmlTextWriter(SignedFileName, new UTF8Encoding(false));
        doc.WriteTo(xmltw);
        xmltw.Close();
    }
    // Verify the signature of an XML file and return the result.
    public static Boolean VerifyXmlFile(String Name)
    {
        // Check the arguments.
        if (Name == null)
            throw new ArgumentNullException("Name");

        // Create a new XML document.
        XmlDocument xmlDocument = new XmlDocument();

        // Format using white spaces.
        xmlDocument.PreserveWhitespace = true;

        // Load the passed XML file into the document.
        xmlDocument.Load(Name);

        // Create a new SignedXml object and pass it
        // the XML document class.
        SignedXml signedXml = new SignedXml(xmlDocument);

        // Find the "Signature" node and create a new
        // XmlNodeList object.
        XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");

        // Load the signature node.
        signedXml.LoadXml((XmlElement)nodeList[0]);

        // Check the signature and return the result.
        return signedXml.CheckSignature();
    }
}
' This example signs an XML file using an
' envelope signature. It then verifies the 
' signed XML.
'
Imports System.Security.Cryptography
Imports System.Security.Cryptography.Xml
Imports System.Text
Imports System.Xml



Module SignVerifyEnvelope



    Sub Main(ByVal args() As String)
        ' Generate a signing key.
        Dim Key As RSA = RSA.Create()

        Try
            ' Specify an element to sign. 
            Dim elements As String() = New String() {"#tag1"}

            ' Sign an XML file and save the signature to a 
            ' new file.
            SignXmlFile("Test.xml", "SignedExample.xml", Key, elements)
            Console.WriteLine("XML file signed.")

            ' Verify the signature of the signed XML.
            Console.WriteLine("Verifying signature...")

            Dim result As Boolean = VerifyXmlFile("SignedExample.xml")

            ' Display the results of the signature verification to \
            ' the console.
            If result Then
                Console.WriteLine("The XML signature is valid.")
            Else
                Console.WriteLine("The XML signature is not valid.")
            End If
        Catch e As CryptographicException
            Console.WriteLine(e.Message)
        Finally
            ' Clear resources associated with the 
            ' RSA instance.
            Key.Clear()
        End Try

    End Sub


    ' Sign an XML file and save the signature in a new file.
    Sub SignXmlFile(ByVal FileName As String, ByVal SignedFileName As String, ByVal Key As RSA, ByVal ElementsToSign() As String)
        ' Check the arguments.  
        If FileName Is Nothing Then
            Throw New ArgumentNullException("FileName")
        End If
        If SignedFileName Is Nothing Then
            Throw New ArgumentNullException("SignedFileName")
        End If
        If Key Is Nothing Then
            Throw New ArgumentNullException("Key")
        End If
        If ElementsToSign Is Nothing Then
            Throw New ArgumentNullException("ElementsToSign")
        End If
        ' Create a new XML document.
        Dim doc As New XmlDocument()

        ' Format the document to ignore white spaces.
        doc.PreserveWhitespace = False

        ' Load the passed XML file using it's name.
        doc.Load(New XmlTextReader(FileName))

        ' Create a SignedXml object.
        Dim signedXml As New SignedXml(doc)

        ' Add the key to the SignedXml document. 
        signedXml.SigningKey = Key

        ' Loop through each passed element to sign 
        ' and create a reference.
        Dim s As String
        For Each s In ElementsToSign
            ' Create a reference to be signed.
            Dim reference As New Reference()
            reference.Uri = s

            ' Add an enveloped transformation to the reference.
            Dim env As New XmlDsigEnvelopedSignatureTransform()
            reference.AddTransform(env)

            ' Add the reference to the SignedXml object.
            signedXml.AddReference(reference)
        Next s

        ' Add an RSAKeyValue KeyInfo (optional; helps recipient find key to validate).
        Dim keyInfo As New KeyInfo()
        keyInfo.AddClause(New RSAKeyValue(CType(Key, RSA)))
        signedXml.KeyInfo = keyInfo

        ' Compute the signature.
        signedXml.ComputeSignature()

        ' Get the XML representation of the signature and save
        ' it to an XmlElement object.
        Dim xmlDigitalSignature As XmlElement = signedXml.GetXml()

        ' Append the element to the XML document.
        doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, True))


        If TypeOf doc.FirstChild Is XmlDeclaration Then
            doc.RemoveChild(doc.FirstChild)
        End If

        ' Save the signed XML document to a file specified
        ' using the passed string.
        Dim xmltw As New XmlTextWriter(SignedFileName, New UTF8Encoding(False))
        doc.WriteTo(xmltw)
        xmltw.Close()

    End Sub

    ' Verify the signature of an XML file and return the result.
    Function VerifyXmlFile(ByVal Name As String) As [Boolean]
        ' Check the arguments.  
        If Name Is Nothing Then
            Throw New ArgumentNullException("Name")
        End If
        ' Create a new XML document.
        Dim xmlDocument As New XmlDocument()

        ' Format using white spaces.
        xmlDocument.PreserveWhitespace = True

        ' Load the passed XML file into the document. 
        xmlDocument.Load(Name)

        ' Create a new SignedXml object and pass it
        ' the XML document class.
        Dim signedXml As New SignedXml(xmlDocument)

        ' Find the "Signature" node and create a new
        ' XmlNodeList object.
        Dim nodeList As XmlNodeList = xmlDocument.GetElementsByTagName("Signature")

        ' Load the signature node.
        signedXml.LoadXml(CType(nodeList(0), XmlElement))

        ' Check the signature and return the result.
        Return signedXml.CheckSignature()

    End Function
End Module

Uwagi

Klasa to implementacja SignedXml platformy .NET składni i przetwarzania xml konsorcjum World Wide Web Consortium (W3C), znana również jako XMLDSIG (PODPIS cyfrowy XML). XMLDSIG to oparty na standardach, międzyoperacyjny sposób podpisywania i weryfikowania wszystkich lub części dokumentu XML lub innych danych, które można adresować z identyfikatora URI (Uniform Resource Identifier).

SignedXml Użyj klasy zawsze, gdy musisz udostępniać podpisane dane XML między aplikacjami lub organizacjami w standardowy sposób. Wszystkie dane podpisane przy użyciu tej klasy można zweryfikować za pomocą dowolnej zgodnej implementacji specyfikacji W3C dla XMLDSIG.

Klasa SignedXml umożliwia utworzenie następujących trzech rodzajów podpisów cyfrowych XML:

Typ podpisu Opis
Sygnatura kopertowa Podpis jest zawarty w podpisanym elemecie XML.
Podpis otaczania Podpisany kod XML znajduje się w elemecie <Signature> .
Podpis odłączony wewnętrzny Podpis i podpisany kod XML znajdują się w tym samym dokumencie, ale żaden z nich nie zawiera drugiego elementu.

Istnieje również czwarty rodzaj podpisu nazywany zewnętrznym odłączonym podpisem, który jest wtedy, gdy dane i podpis znajdują się w oddzielnych dokumentach XML. Sygnatury odłączone zewnętrznie nie są obsługiwane przez klasę SignedXml .

Struktura podpisu XML

XMLDSIG tworzy <Signature> element, który zawiera podpis cyfrowy dokumentu XML lub innych danych, które można zasłaniać przy użyciu identyfikatora URI. Element <Signature> może opcjonalnie zawierać informacje o tym, gdzie znaleźć klucz, który zweryfikuje podpis i który algorytm kryptograficzny został użyty do podpisywania. Podstawowa struktura jest następująca:

<Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">  
    <SignedInfo>  
      <CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>  
      <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>  
      <Reference URI="">  
        <Transforms>  
          <Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>  
        </Transforms>  
        <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>  
        <DigestValue>Base64EncodedValue==</DigestValue>  
      </Reference>  
    </SignedInfo>  
    <SignatureValue>AnotherBase64EncodedValue===</SignatureValue>  
</Signature>

Główne części tej struktury to:

  • Element <CanonicalizationMethod>

    Określa reguły ponownego zapisywania Signature elementu z kodu XML/tekstu do bajtów na potrzeby walidacji podpisu. Wartość domyślna na platformie .NET to http://www.w3.org/TR/2001/REC-xml-c14n-20010315, która identyfikuje zaufany algorytm. Ten element jest reprezentowany przez SignedInfo.CanonicalizationMethod właściwość .

  • Element <SignatureMethod>

    Określa algorytm używany do generowania i walidacji podpisu, który został zastosowany do <Signature> elementu w celu wygenerowania wartości w <SignatureValue>pliku . W poprzednim przykładzie wartość http://www.w3.org/2000/09/xmldsig#rsa-sha1 identyfikuje podpis SHA-1 RSA PKCS1. Ze względu na problemy z kolizją z algorytmem SHA-1 firma Microsoft zaleca model zabezpieczeń oparty na algorytmie SHA-256 lub lepszym. Ten element jest reprezentowany przez SignatureMethod właściwość .

  • Element <SignatureValue>

    Określa podpis kryptograficzny elementu <Signature> . Jeśli ten podpis nie zostanie zweryfikowany, część <Signature> bloku została naruszona, a dokument jest uznawany za nieprawidłowy. Tak długo, jak <CanonicalizationMethod> wartość jest godna zaufania, ta wartość jest wysoce odporna na manipulowanie. Ten element jest reprezentowany przez SignatureValue właściwość .

  • Atrybut URI <Reference> elementu

    Określa obiekt danych przy użyciu odwołania identyfikatora URI. Ten atrybut jest reprezentowany przez Reference.Uri właściwość .

    • Nie określa atrybutu URI , czyli ustawiania Reference.Uri właściwości na null, oznacza, że aplikacja odbierającą ma znać tożsamość obiektu. W większości przypadków null identyfikator URI spowoduje zgłoszenie wyjątku. Nie używaj identyfikatora null URI, chyba że aplikacja współdziała z protokołem, który go wymaga.

    • Ustawienie atrybutu na URI pusty ciąg wskazuje, że element główny dokumentu jest podpisany, forma podpisu kopertowego.

    • Jeśli wartość atrybutu URI zaczyna się od #, wartość musi zostać rozpoznana jako element w bieżącym dokumencie. Ten formularz może być używany z dowolnym z obsługiwanych typów podpisów (sygnatura kopertowa, otaczanie podpisu lub wewnętrzny odłączony podpis).

    • Wszystkie inne elementy są uznawane za sygnaturę odłączonego zasobu zewnętrznego i nie są obsługiwane przez klasę SignedXml .

  • Element <Transforms>

    Zawiera uporządkowaną listę <Transform> elementów opisujących sposób uzyskiwania obiektu danych szyfrowanego przez znakatora. Algorytm przekształcania jest podobny do metody kanonicznej, ale zamiast ponownie zapisywać <Signature> element, zapisuje ponownie zawartość zidentyfikowaną przez URI atrybut <Reference> elementu. Element <Transforms> jest reprezentowany przez klasę TransformChain .

    • Każdy algorytm przekształcania jest definiowany jako pobieranie kodu XML (zestawu węzłów XPath) lub bajtów jako danych wejściowych. Jeśli format bieżących danych różni się od wymagań wejściowych transformacji, stosowane są reguły konwersji.

    • Każdy algorytm przekształcania jest definiowany jako tworzenie kodu XML lub bajtów jako danych wyjściowych.

    • Jeśli dane wyjściowe ostatniego algorytmu przekształcania nie są zdefiniowane w bajtach (lub nie określono żadnych przekształceń), metoda kanoniczna jest używana jako niejawna transformacja (nawet jeśli w <CanonicalizationMethod> elemecie określono inny algorytm).

    • Wartość http://www.w3.org/2000/09/xmldsig#enveloped-signature algorytmu przekształcania koduje regułę, która jest interpretowana jako usuwanie <Signature> elementu z dokumentu. W przeciwnym razie weryfikator sygnatury kopertowej będzie szyfrował dokument, w tym podpis, ale podpis przetrawiłby dokument przed zastosowaniem podpisu, co prowadzi do różnych odpowiedzi.

  • Element <DigestMethod>

    Identyfikuje metodę skrótu (skrót kryptograficzny), która ma być stosowana w przekształconej zawartości identyfikowanej przez URI atrybut <Reference> elementu. Jest to reprezentowane przez Reference.DigestMethod właściwość .

Wybieranie metody kanonicznej

Jeśli nie współpracujemy ze specyfikacją, która wymaga użycia innej wartości, zalecamy użycie domyślnej metody canonicalization platformy .NET, czyli algorytmu XML-C14N 1.0, którego wartość to http://www.w3.org/TR/2001/REC-xml-c14n-20010315. Algorytm XML-C14N 1.0 jest wymagany do obsługi przez wszystkie implementacje XMLDSIG, szczególnie ponieważ jest to niejawna ostateczna transformacja do zastosowania.

Istnieją wersje algorytmów kanonizacji, które obsługują zachowywanie komentarzy. Metody kanonizacji zachowujące komentarz nie są zalecane, ponieważ naruszają zasadę "znak, co jest postrzegane". Oznacza to, że komentarze w elemecie <Signature> nie zmienią logiki przetwarzania pod kątem sposobu wykonywania podpisu, tylko tego, jaka jest wartość podpisu. W połączeniu ze słabym algorytmem podpisu, zezwolenie na dołączanie komentarzy daje atakującemu niepotrzebną swobodę wymusić kolizję skrótu, co sprawia, że naruszony dokument wydaje się uzasadniony. W .NET Framework domyślnie obsługiwane są tylko wbudowane moduły kanoniczne. Aby obsługiwać dodatkowe lub niestandardowe moduły kanoniczne, zobacz SafeCanonicalizationMethods właściwość . Jeśli dokument używa metody kanonicznej, która nie znajduje się w kolekcji reprezentowanej przez SafeCanonicalizationMethods właściwość, CheckSignature metoda zwróci falsewartość .

Uwaga

Niezwykle defensywna aplikacja może usunąć wszelkie wartości, których nie oczekuje, że osoby podpisające będą używane z kolekcji SafeCanonicalizationMethods .

Czy wartości referencyjne są bezpieczne przed manipulowaniem?

Tak, <Reference> wartości są bezpieczne przed manipulowaniem. Platforma .NET weryfikuje <SignatureValue> obliczenia przed przetworzeniem dowolnych <Reference> wartości i skojarzonych z nimi przekształceń, a także zostanie wcześnie przerwana, aby uniknąć potencjalnie złośliwych instrukcji przetwarzania.

Wybieranie elementów do podpisania

Zalecamy użycie wartości "" dla atrybutu URI (lub ustawienie Uri właściwości na pusty ciąg), jeśli to możliwe. Oznacza to, że cały dokument jest uznawany za obliczenia szyfrowane, co oznacza, że cały dokument jest chroniony przed manipulowaniem.

Bardzo często można zobaczyć URI wartości w postaci kotwic, takich jak #foo, odwołując się do elementu, którego atrybut id to "foo". Niestety, łatwo jest to manipulować, ponieważ obejmuje to tylko zawartość elementu docelowego, a nie kontekst. Nadużywanie tego rozróżnienia jest nazywane zawijaniem podpisów XML (XSW).

Jeśli aplikacja uważa, że komentarze są semantyczne (co nie jest powszechne w przypadku obsługi kodu XML), należy użyć polecenia "#xpointer(/)" zamiast "", a "#xpointer(id('foo'))" zamiast "#foo". Wersje #xpointer są interpretowane jako komentarze, podczas gdy formularze shortname wykluczają komentarze.

Jeśli musisz zaakceptować dokumenty, które są tylko częściowo chronione i chcesz mieć pewność, że czytasz tę samą zawartość, którą chroni sygnatura GetIdElement , użyj metody .

Zagadnienia dotyczące zabezpieczeń elementu KeyInfo

Dane w opcjonalnym elemecie <KeyInfo> ( KeyInfo czyli właściwości), która zawiera klucz do zweryfikowania podpisu, nie powinny być zaufane.

W szczególności, gdy KeyInfo wartość reprezentuje gołe RSA, DSA lub ECDSA klucza publicznego, dokument mógł zostać naruszony, pomimo CheckSignature metody raportowania, że podpis jest prawidłowy. Może się tak zdarzyć, ponieważ jednostka wykonująca manipulację musi wygenerować nowy klucz i ponownie podpisać zmodyfikowany dokument przy użyciu tego nowego klucza. Tak więc, chyba że aplikacja sprawdza, czy klucz publiczny jest oczekiwaną wartością, dokument powinien być traktowany tak, jakby został naruszony. Wymaga to, aby aplikacja zbadała klucz publiczny osadzony w dokumencie i zweryfikowała go na liście znanych wartości kontekstu dokumentu. Jeśli na przykład dokument może zostać wystawiony przez znanego użytkownika, należy sprawdzić klucz na liście znanych kluczy używanych przez tego użytkownika.

Klucz można również sprawdzić po przetworzeniu dokumentu przy użyciu CheckSignatureReturningKey metody zamiast metody CheckSignature . Jednak w celu zapewnienia optymalnego bezpieczeństwa należy wcześniej zweryfikować klucz.

Alternatywnie rozważ wypróbowanie zarejestrowanych kluczy publicznych użytkownika, a nie odczytanie elementów w elemencie <KeyInfo> .

Zagadnienia dotyczące zabezpieczeń elementu X509Data

Opcjonalny <X509Data> element jest elementem podrzędnym <KeyInfo> elementu i zawiera co najmniej jeden certyfikat X509 lub identyfikatory certyfikatów X509. Dane w <X509Data> elemecie nie powinny być również z natury zaufane.

Podczas weryfikowania dokumentu z elementem osadzonym <X509Data> platforma .NET sprawdza tylko, czy dane są rozpoznawane jako certyfikat X509, którego klucz publiczny może zostać pomyślnie użyty do zweryfikowania podpisu dokumentu. W przeciwieństwie do wywoływania CheckSignature metody z parametrem ustawionym na verifySignatureOnly false, nie jest wykonywane sprawdzanie odwołania, nie jest sprawdzane żadne zaufanie łańcucha i nie jest weryfikowane żadne wygaśnięcie. Nawet jeśli aplikacja wyodrębnia sam certyfikat i przekazuje go do CheckSignature metody z parametrem ustawionym verifySignatureOnly na false, to nadal nie jest wystarczająca weryfikacja, aby zapobiec manipulowaniu dokumentem. Certyfikat nadal musi zostać zweryfikowany jako odpowiedni dla podpisanego dokumentu.

Użycie osadzonego certyfikatu podpisywania może zapewnić przydatne strategie rotacji kluczy, niezależnie od tego, czy w sekcji, czy w <X509Data> zawartości dokumentu. W przypadku korzystania z tego podejścia aplikacja powinna ręcznie wyodrębnić certyfikat i przeprowadzić walidację podobną do:

  • Certyfikat został wystawiony bezpośrednio lub za pośrednictwem łańcucha przez urząd certyfikacji, którego certyfikat publiczny jest osadzony w aplikacji.

    Korzystanie z listy zaufania dostarczonej przez system operacyjny bez dodatkowych kontroli, takich jak znana nazwa podmiotu, nie jest wystarczające, aby zapobiec manipulacji w systemie SignedXml.

  • Certyfikat został zweryfikowany, aby nie wygasł w momencie podpisywania dokumentu (lub "teraz" na potrzeby przetwarzania dokumentów niemal w czasie rzeczywistym).

  • W przypadku certyfikatów długotrwałych wystawionych przez urząd certyfikacji, który obsługuje odwoływanie, sprawdź, czy certyfikat nie został odwołany.

  • Podmiot certyfikatu jest weryfikowany zgodnie z potrzebami bieżącego dokumentu.

Wybieranie algorytmu przekształcania

Jeśli pracujesz ze specyfikacją, która określa określone wartości (takie jak XrML), musisz postępować zgodnie ze specyfikacją. Jeśli masz sygnaturę kopertową (np. podczas podpisywania całego dokumentu), musisz użyć http://www.w3.org/2000/09/xmldsig#enveloped-signature elementu (reprezentowanego przez klasę XmlDsigEnvelopedSignatureTransform ). Można również określić niejawne przekształcenie XML-C14N, ale nie jest to konieczne. W przypadku dołączania lub odłączania podpisu nie są wymagane żadne przekształcenia. Niejawne przekształcenie XML-C14N zajmuje się wszystkim.

Dzięki aktualizacji zabezpieczeń wprowadzonej przez biuletyn zabezpieczeń firmy Microsoft MS16-035 platforma .NET ograniczyła, jakie przekształcenia mogą być używane domyślnie w weryfikacji dokumentu, a niezaufane przekształcenia powodują, że CheckSignature zawsze zwracany jest element false. W szczególności przekształcenia wymagające dodatkowych danych wejściowych (określonych jako elementy podrzędne w kodzie XML) nie są już dozwolone ze względu na ich podatność na nadużycia przez złośliwych użytkowników. W3C zaleca unikanie przekształceń XPath i XSLT, które są dwoma głównymi transformacjami, na które mają wpływ te ograniczenia.

Problem z odwołaniami zewnętrznymi

Jeśli aplikacja nie weryfikuje, czy odwołania zewnętrzne wydają się odpowiednie dla bieżącego kontekstu, mogą być nadużywane w sposób zapewniający wiele luk w zabezpieczeniach (w tym odmowa usługi, rozproszona odmowa usługi, ujawnienie informacji, obejście podpisu i zdalne wykonywanie kodu). Nawet jeśli aplikacja miała zweryfikować identyfikator URI odwołania zewnętrznego, problem z zasobem jest ładowany dwa razy: raz, gdy aplikacja go odczytuje, a raz po SignedXml jego odczytaniu. Ponieważ nie ma gwarancji, że aplikacja odczytuje i weryfikuje kroki z tą samą zawartością, podpis nie zapewnia wiarygodności.

Biorąc pod uwagę ryzyko odwołań zewnętrznych, SignedXml zgłasza wyjątek w przypadku napotkania odwołania zewnętrznego. Aby uzyskać więcej informacji na temat tego problemu, zobacz artykuł kb 3148821.

Konstruktory

SignedXml()

Inicjuje nowe wystąpienie klasy SignedXml.

SignedXml(XmlDocument)

Inicjuje SignedXml nowe wystąpienie klasy z określonego dokumentu XML.

SignedXml(XmlElement)

Inicjuje SignedXml nowe wystąpienie klasy z określonego XmlElement obiektu.

Pola

m_signature

Signature Reprezentuje obiekt bieżącego SignedXml obiektu.

m_strSigningKeyName

Reprezentuje nazwę zainstalowanego klucza, który ma być używany do podpisywania SignedXml obiektu.

XmlDecryptionTransformUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla przekształcenia odszyfrowywania trybu XML. To pole jest stałe.

XmlDsigBase64TransformUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla przekształcenia podstawowego 64. To pole jest stałe.

XmlDsigC14NTransformUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) transformacji Canonical XML. To pole jest stałe.

XmlDsigC14NWithCommentsTransformUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla przekształcenia Canonical XML z komentarzami. To pole jest stałe.

XmlDsigCanonicalizationUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla standardowego algorytmu kanonizacji dla podpisów cyfrowych XML. To pole jest stałe.

XmlDsigCanonicalizationWithCommentsUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla standardowego algorytmu kanonizacji dla podpisów cyfrowych XML i zawiera komentarze. To pole jest stałe.

XmlDsigDSAUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla standardowego DSA algorytmu podpisów cyfrowych XML. To pole jest stałe.

XmlDsigEnvelopedSignatureTransformUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla przekształcenia sygnatury kopertowej. To pole jest stałe.

XmlDsigExcC14NTransformUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) na potrzeby wyłącznej kanonizacji XML. To pole jest stałe.

XmlDsigExcC14NWithCommentsTransformUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) na potrzeby wyłącznej kanonizacji XML z komentarzami. To pole jest stałe.

XmlDsigHMACSHA1Url

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla standardowego HMACSHA1 algorytmu podpisów cyfrowych XML. To pole jest stałe.

XmlDsigMinimalCanonicalizationUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla standardowego algorytmu minimalnej kanonizacji dla podpisów cyfrowych XML. To pole jest stałe.

XmlDsigNamespaceUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla standardowej przestrzeni nazw dla podpisów cyfrowych XML. To pole jest stałe.

XmlDsigRSASHA1Url

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla standardowej RSA metody podpisu dla podpisów cyfrowych XML. To pole jest stałe.

XmlDsigRSASHA256Url

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla RSA odmiany metody podpisu SHA-256 dla podpisów cyfrowych XML. To pole jest stałe.

XmlDsigRSASHA384Url

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla RSA odmiany metody podpisu SHA-384 dla podpisów cyfrowych XML. To pole jest stałe.

XmlDsigRSASHA512Url

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla RSA odmiany metody podpisu SHA-512 dla podpisów cyfrowych XML. To pole jest stałe.

XmlDsigSHA1Url

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla standardowej SHA1 metody skrótu dla podpisów cyfrowych XML. To pole jest stałe.

XmlDsigSHA256Url

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla standardowej SHA256 metody skrótu dla podpisów cyfrowych XML. To pole jest stałe.

XmlDsigSHA384Url

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla standardowej SHA384 metody skrótu dla podpisów cyfrowych XML. To pole jest stałe.

XmlDsigSHA512Url

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla standardowej SHA512 metody skrótu dla podpisów cyfrowych XML. To pole jest stałe.

XmlDsigXPathTransformUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla języka ścieżki XML (XPath). To pole jest stałe.

XmlDsigXsltTransformUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla przekształceń XSLT. To pole jest stałe.

XmlLicenseTransformUrl

Reprezentuje identyfikator URI (Uniform Resource Identifier) dla algorytmu przekształcania licencji używanego do normalizacji licencji XrML dla podpisów.

Właściwości

EncryptedXml

Pobiera lub ustawia EncryptedXml obiekt definiujący reguły przetwarzania szyfrowania XML.

KeyInfo

Pobiera lub ustawia KeyInfo obiekt bieżącego SignedXml obiektu.

Resolver

Ustawia bieżący XmlResolver obiekt.

SafeCanonicalizationMethods

Pobiera nazwy metod, których algorytmy kanoniczne są jawnie dozwolone.

Signature

Signature Pobiera obiekt bieżącego SignedXml obiektu.

SignatureFormatValidator

Pobiera delegata, który zostanie wywołany w celu zweryfikowania formatu (a nie zabezpieczeń kryptograficznych) podpisu XML.

SignatureLength

Pobiera długość podpisu dla bieżącego SignedXml obiektu.

SignatureMethod

Pobiera metodę podpisu bieżącego SignedXml obiektu.

SignatureValue

Pobiera wartość podpisu bieżącego SignedXml obiektu.

SignedInfo

SignedInfo Pobiera obiekt bieżącego SignedXml obiektu.

SigningKey

Pobiera lub ustawia klucz algorytmu asymetrycznego używany do podpisywania SignedXml obiektu.

SigningKeyName

Pobiera lub ustawia nazwę zainstalowanego klucza, który ma być używany do podpisywania SignedXml obiektu.

Metody

AddObject(DataObject)

DataObject Dodaje obiekt do listy obiektów do podpisania.

AddReference(Reference)

Reference Dodaje obiekt do SignedXml obiektu opisującego metodę skrótu, wartość skrótu i przekształcenie w celu utworzenia podpisu cyfrowego XML.

CheckSignature()

Określa, czy Signature właściwość weryfikuje użycie klucza publicznego w podpisie.

CheckSignature(AsymmetricAlgorithm)

Określa, czy Signature właściwość sprawdza określony klucz.

CheckSignature(KeyedHashAlgorithm)

Określa, czy Signature właściwość sprawdza algorytm określonego kodu uwierzytelniania komunikatów (MAC).

CheckSignature(X509Certificate2, Boolean)

Określa, czy Signature właściwość sprawdza określony X509Certificate2 obiekt i, opcjonalnie, czy certyfikat jest prawidłowy.

CheckSignatureReturningKey(AsymmetricAlgorithm)

Określa, czy Signature właściwość weryfikuje użycie klucza publicznego w podpisie.

ComputeSignature()

Oblicza podpis cyfrowy XML.

ComputeSignature(KeyedHashAlgorithm)

Oblicza podpis cyfrowy XML przy użyciu określonego algorytmu kodu uwierzytelniania komunikatów (MAC).

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetIdElement(XmlDocument, String)

XmlElement Zwraca obiekt o określonym identyfikatorze z określonego XmlDocument obiektu.

GetPublicKey()

Zwraca klucz publiczny podpisu.

GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
GetXml()

Zwraca reprezentację SignedXml XML obiektu.

LoadXml(XmlElement)

SignedXml Ładuje stan z elementu XML.

MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też