Freigeben über


XmlDsigEnvelopedSignatureTransform Konstruktoren

Definition

Initialisiert eine neue Instanz der XmlDsigEnvelopedSignatureTransform-Klasse.

Überlädt

XmlDsigEnvelopedSignatureTransform()

Initialisiert eine neue Instanz der XmlDsigEnvelopedSignatureTransform-Klasse.

XmlDsigEnvelopedSignatureTransform(Boolean)

Initialisiert eine neue Instanz der XmlDsigEnvelopedSignatureTransform-Klasse mit Kommentaren, sofern angegeben.

XmlDsigEnvelopedSignatureTransform()

Quelle:
XmlDsigEnvelopedSignatureTransform.cs
Quelle:
XmlDsigEnvelopedSignatureTransform.cs
Quelle:
XmlDsigEnvelopedSignatureTransform.cs

Initialisiert eine neue Instanz der XmlDsigEnvelopedSignatureTransform-Klasse.

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

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie Member der XmlDsigEnvelopedSignatureTransform -Klasse verwendet werden.

// Sign an XML file and save the signature in a new file.
void SignXmlFile( String^ FileName, String^ SignedFileName, RSA^ Key )
{
   
   // 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 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 );
   
   // Add an RSAKeyValue KeyInfo (optional; helps recipient find key to validate).
   KeyInfo^ keyInfo = gcnew KeyInfo;
   keyInfo->AddClause( gcnew RSAKeyValue( safe_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 ( (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();
}
// Sign an XML file and save the signature in a new file.
public static void SignXmlFile(string FileName, string SignedFileName, RSA Key)
{
    // 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;

    // 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);

    // 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();
}
' Sign an XML file and save the signature in a new file.
Public Shared Sub SignXmlFile(FileName As String, SignedFileName As String, Key As RSA)
   ' 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
   
   ' 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)
   
   
   ' 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

Gilt für:

XmlDsigEnvelopedSignatureTransform(Boolean)

Quelle:
XmlDsigEnvelopedSignatureTransform.cs
Quelle:
XmlDsigEnvelopedSignatureTransform.cs
Quelle:
XmlDsigEnvelopedSignatureTransform.cs

Initialisiert eine neue Instanz der XmlDsigEnvelopedSignatureTransform-Klasse mit Kommentaren, sofern angegeben.

public:
 XmlDsigEnvelopedSignatureTransform(bool includeComments);
public XmlDsigEnvelopedSignatureTransform (bool includeComments);
new System.Security.Cryptography.Xml.XmlDsigEnvelopedSignatureTransform : bool -> System.Security.Cryptography.Xml.XmlDsigEnvelopedSignatureTransform
Public Sub New (includeComments As Boolean)

Parameter

includeComments
Boolean

true, wenn Kommentare eingeschlossen werden sollen, andernfalls false.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie Sie den XmlDsigEnvelopedSignatureTransform Konstruktor mit dem Boolean Wert von true verwenden, um Kommentare einzuschließen. Dieses Codebeispiel ist Teil eines größeren Beispiels, das für die XmlDsigEnvelopedSignatureTransform-Klasse bereitgestellt wird.

bool IncludeComments = true;
// This transform is created for demonstration purposes.
XmlDsigEnvelopedSignatureTransform^ secondTransform =
    gcnew XmlDsigEnvelopedSignatureTransform(IncludeComments);
bool IncludeComments = true;
// This transform is created for demonstration purposes.
XmlDsigEnvelopedSignatureTransform secondTransform =
    new XmlDsigEnvelopedSignatureTransform(IncludeComments);
Dim IncludeComments As Boolean = True
' This transform is created for demonstration purposes.
Dim secondTransform As _
    New XmlDsigEnvelopedSignatureTransform(IncludeComments)

Gilt für: