PackageDigitalSignatureManager.Sign Methode
Definition
Wichtig
Einige Informationen beziehen sich auf Vorabversionen, die vor dem Release ggf. grundlegend überarbeitet werden. Microsoft übernimmt hinsichtlich der hier bereitgestellten Informationen keine Gewährleistungen, seien sie ausdrücklich oder konkludent.
Signiert eine Liste der Paketteile mit einem angegebenen X.509-Zertifikat.
Überlädt
| Name | Beschreibung |
|---|---|
| Sign(IEnumerable<Uri>) |
Fordert den Benutzer auf, ein X.509-Zertifikat einzugeben, das dann zum digitalen Signieren einer angegebenen Liste von Paketteilen verwendet wird. |
| Sign(IEnumerable<Uri>, X509Certificate) |
Signiert eine Liste der Paketteile mit einem bestimmten X.509-Zertifikat. |
| Sign(IEnumerable<Uri>, X509Certificate, IEnumerable<PackageRelationshipSelector>) |
Signiert eine Liste der Paketteile und Paketbeziehungen mit einem bestimmten X.509-Zertifikat. |
| Sign(IEnumerable<Uri>, X509Certificate, IEnumerable<PackageRelationshipSelector>, String) |
Signiert eine Liste der Paketteile und Paketbeziehungen mit einem bestimmten X.509-Zertifikat und -Bezeichner (ID). |
| Sign(IEnumerable<Uri>, X509Certificate, IEnumerable<PackageRelationshipSelector>, String, IEnumerable<DataObject>, IEnumerable<Reference>) |
Signiert eine Liste von Paketteilen, Paketbeziehungen oder benutzerdefinierten Objekten mit einem angegebenen X.509-Zertifikat- und Signaturbezeichner (ID). |
Beispiele
Das folgende Beispiel zeigt die Schritte zum digitalen Signieren einer Liste von Teilen in einem Package.
private static void SignAllParts(Package package)
{
if (package == null)
throw new ArgumentNullException("SignAllParts(package)");
// Create the DigitalSignature Manager
PackageDigitalSignatureManager dsm =
new PackageDigitalSignatureManager(package);
dsm.CertificateOption =
CertificateEmbeddingOption.InSignaturePart;
// Create a list of all the part URIs in the package to sign
// (GetParts() also includes PackageRelationship parts).
System.Collections.Generic.List<Uri> toSign =
new System.Collections.Generic.List<Uri>();
foreach (PackagePart packagePart in package.GetParts())
{
// Add all package parts to the list for signing.
toSign.Add(packagePart.Uri);
}
// Add the URI for SignatureOrigin PackageRelationship part.
// The SignatureOrigin relationship is created when Sign() is called.
// Signing the SignatureOrigin relationship disables counter-signatures.
toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin));
// Also sign the SignatureOrigin part.
toSign.Add(dsm.SignatureOrigin);
// Add the package relationship to the signature origin to be signed.
toSign.Add(PackUriHelper.GetRelationshipPartUri(new Uri("/", UriKind.RelativeOrAbsolute)));
// Sign() will prompt the user to select a Certificate to sign with.
try
{
dsm.Sign(toSign);
}
// If there are no certificates or the SmartCard manager is
// not running, catch the exception and show an error message.
catch (CryptographicException ex)
{
MessageBox.Show(
"Cannot Sign\n" + ex.Message,
"No Digital Certificates Available",
MessageBoxButton.OK,
MessageBoxImage.Exclamation);
}
}// end:SignAllParts()
Private Shared Sub SignAllParts(ByVal package As Package)
If package Is Nothing Then
Throw New ArgumentNullException("SignAllParts(package)")
End If
' Create the DigitalSignature Manager
Dim dsm As New PackageDigitalSignatureManager(package)
dsm.CertificateOption = CertificateEmbeddingOption.InSignaturePart
' Create a list of all the part URIs in the package to sign
' (GetParts() also includes PackageRelationship parts).
Dim toSign As New System.Collections.Generic.List(Of Uri)()
For Each packagePart As PackagePart In package.GetParts()
' Add all package parts to the list for signing.
toSign.Add(packagePart.Uri)
Next
' Add the URI for SignatureOrigin PackageRelationship part.
' The SignatureOrigin relationship is created when Sign() is called.
' Signing the SignatureOrigin relationship disables counter-signatures.
toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin))
' Also sign the SignatureOrigin part.
toSign.Add(dsm.SignatureOrigin)
' Add the package relationship to the signature origin to be signed.
toSign.Add(PackUriHelper.GetRelationshipPartUri(New Uri("/", UriKind.RelativeOrAbsolute)))
' Sign() will prompt the user to select a Certificate to sign with.
Try
dsm.Sign(toSign)
Catch ex As CryptographicException
' If there are no certificates or the SmartCard manager is
' not running, catch the exception and show an error message.
MessageBox.Show("Cannot Sign" & vbLf & ex.Message, "No Digital Certificates Available", MessageBoxButton.OK, MessageBoxImage.Exclamation)
End Try
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
' end:SignAllParts()
Sign(IEnumerable<Uri>)
Fordert den Benutzer auf, ein X.509-Zertifikat einzugeben, das dann zum digitalen Signieren einer angegebenen Liste von Paketteilen verwendet wird.
public:
System::IO::Packaging::PackageDigitalSignature ^ Sign(System::Collections::Generic::IEnumerable<Uri ^> ^ parts);
public System.IO.Packaging.PackageDigitalSignature Sign(System.Collections.Generic.IEnumerable<Uri> parts);
member this.Sign : seq<Uri> -> System.IO.Packaging.PackageDigitalSignature
Public Function Sign (parts As IEnumerable(Of Uri)) As PackageDigitalSignature
Parameter
- parts
- IEnumerable<Uri>
Die Liste der URIs (Uniform Resource Identifiers) für die PackagePart zu signierenden Elemente.
Gibt zurück
Die digitale Signatur, die zum Signieren der Liste von parts.
Beispiele
Das folgende Beispiel zeigt, wie Sie eine Liste von Paketteilen digital signieren.
private static void SignAllParts(Package package)
{
if (package == null)
throw new ArgumentNullException("SignAllParts(package)");
// Create the DigitalSignature Manager
PackageDigitalSignatureManager dsm =
new PackageDigitalSignatureManager(package);
dsm.CertificateOption =
CertificateEmbeddingOption.InSignaturePart;
// Create a list of all the part URIs in the package to sign
// (GetParts() also includes PackageRelationship parts).
System.Collections.Generic.List<Uri> toSign =
new System.Collections.Generic.List<Uri>();
foreach (PackagePart packagePart in package.GetParts())
{
// Add all package parts to the list for signing.
toSign.Add(packagePart.Uri);
}
// Add the URI for SignatureOrigin PackageRelationship part.
// The SignatureOrigin relationship is created when Sign() is called.
// Signing the SignatureOrigin relationship disables counter-signatures.
toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin));
// Also sign the SignatureOrigin part.
toSign.Add(dsm.SignatureOrigin);
// Add the package relationship to the signature origin to be signed.
toSign.Add(PackUriHelper.GetRelationshipPartUri(new Uri("/", UriKind.RelativeOrAbsolute)));
// Sign() will prompt the user to select a Certificate to sign with.
try
{
dsm.Sign(toSign);
}
// If there are no certificates or the SmartCard manager is
// not running, catch the exception and show an error message.
catch (CryptographicException ex)
{
MessageBox.Show(
"Cannot Sign\n" + ex.Message,
"No Digital Certificates Available",
MessageBoxButton.OK,
MessageBoxImage.Exclamation);
}
}// end:SignAllParts()
Private Shared Sub SignAllParts(ByVal package As Package)
If package Is Nothing Then
Throw New ArgumentNullException("SignAllParts(package)")
End If
' Create the DigitalSignature Manager
Dim dsm As New PackageDigitalSignatureManager(package)
dsm.CertificateOption = CertificateEmbeddingOption.InSignaturePart
' Create a list of all the part URIs in the package to sign
' (GetParts() also includes PackageRelationship parts).
Dim toSign As New System.Collections.Generic.List(Of Uri)()
For Each packagePart As PackagePart In package.GetParts()
' Add all package parts to the list for signing.
toSign.Add(packagePart.Uri)
Next
' Add the URI for SignatureOrigin PackageRelationship part.
' The SignatureOrigin relationship is created when Sign() is called.
' Signing the SignatureOrigin relationship disables counter-signatures.
toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin))
' Also sign the SignatureOrigin part.
toSign.Add(dsm.SignatureOrigin)
' Add the package relationship to the signature origin to be signed.
toSign.Add(PackUriHelper.GetRelationshipPartUri(New Uri("/", UriKind.RelativeOrAbsolute)))
' Sign() will prompt the user to select a Certificate to sign with.
Try
dsm.Sign(toSign)
Catch ex As CryptographicException
' If there are no certificates or the SmartCard manager is
' not running, catch the exception and show an error message.
MessageBox.Show("Cannot Sign" & vbLf & ex.Message, "No Digital Certificates Available", MessageBoxButton.OK, MessageBoxImage.Exclamation)
End Try
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
' end:SignAllParts()
Hinweise
Um das Dialogfeld für die Zertifikatauswahl zu einem bestimmten Fenster modal zu machen, legen Sie die ParentWindow Eigenschaft vor dem Aufrufen Signfest.
Sign fordert keine Zertifikate auf, wenn keines im Standardzertifikatspeicher vorhanden ist.
Gilt für:
Sign(IEnumerable<Uri>, X509Certificate)
Signiert eine Liste der Paketteile mit einem bestimmten X.509-Zertifikat.
public:
System::IO::Packaging::PackageDigitalSignature ^ Sign(System::Collections::Generic::IEnumerable<Uri ^> ^ parts, System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate);
public System.IO.Packaging.PackageDigitalSignature Sign(System.Collections.Generic.IEnumerable<Uri> parts, System.Security.Cryptography.X509Certificates.X509Certificate certificate);
member this.Sign : seq<Uri> * System.Security.Cryptography.X509Certificates.X509Certificate -> System.IO.Packaging.PackageDigitalSignature
Public Function Sign (parts As IEnumerable(Of Uri), certificate As X509Certificate) As PackageDigitalSignature
Parameter
- parts
- IEnumerable<Uri>
Die Liste der URIs (Uniform Resource Identifiers) für die PackagePart zu signierenden Elemente.
- certificate
- X509Certificate
Das X.509-Zertifikat, das zum digitalen Signieren jedes der angegebenen Zertifikate partsverwendet werden soll.
Gibt zurück
Die digitale Signatur, die verwendet wird, um die angegebene Liste von parts; zu signieren, oder null wenn kein Zertifikat gefunden werden konnte oder der Benutzer im Dialogfeld für die Zertifikatauswahl auf "Abbrechen" geklickt hat.
Beispiele
Das folgende Beispiel zeigt, wie Sie eine Liste von Teilen in einer Package.
private static void SignAllParts(Package package)
{
if (package == null)
throw new ArgumentNullException("SignAllParts(package)");
// Create the DigitalSignature Manager
PackageDigitalSignatureManager dsm =
new PackageDigitalSignatureManager(package);
dsm.CertificateOption =
CertificateEmbeddingOption.InSignaturePart;
// Create a list of all the part URIs in the package to sign
// (GetParts() also includes PackageRelationship parts).
System.Collections.Generic.List<Uri> toSign =
new System.Collections.Generic.List<Uri>();
foreach (PackagePart packagePart in package.GetParts())
{
// Add all package parts to the list for signing.
toSign.Add(packagePart.Uri);
}
// Add the URI for SignatureOrigin PackageRelationship part.
// The SignatureOrigin relationship is created when Sign() is called.
// Signing the SignatureOrigin relationship disables counter-signatures.
toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin));
// Also sign the SignatureOrigin part.
toSign.Add(dsm.SignatureOrigin);
// Add the package relationship to the signature origin to be signed.
toSign.Add(PackUriHelper.GetRelationshipPartUri(new Uri("/", UriKind.RelativeOrAbsolute)));
// Sign() will prompt the user to select a Certificate to sign with.
try
{
dsm.Sign(toSign);
}
// If there are no certificates or the SmartCard manager is
// not running, catch the exception and show an error message.
catch (CryptographicException ex)
{
MessageBox.Show(
"Cannot Sign\n" + ex.Message,
"No Digital Certificates Available",
MessageBoxButton.OK,
MessageBoxImage.Exclamation);
}
}// end:SignAllParts()
Private Shared Sub SignAllParts(ByVal package As Package)
If package Is Nothing Then
Throw New ArgumentNullException("SignAllParts(package)")
End If
' Create the DigitalSignature Manager
Dim dsm As New PackageDigitalSignatureManager(package)
dsm.CertificateOption = CertificateEmbeddingOption.InSignaturePart
' Create a list of all the part URIs in the package to sign
' (GetParts() also includes PackageRelationship parts).
Dim toSign As New System.Collections.Generic.List(Of Uri)()
For Each packagePart As PackagePart In package.GetParts()
' Add all package parts to the list for signing.
toSign.Add(packagePart.Uri)
Next
' Add the URI for SignatureOrigin PackageRelationship part.
' The SignatureOrigin relationship is created when Sign() is called.
' Signing the SignatureOrigin relationship disables counter-signatures.
toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin))
' Also sign the SignatureOrigin part.
toSign.Add(dsm.SignatureOrigin)
' Add the package relationship to the signature origin to be signed.
toSign.Add(PackUriHelper.GetRelationshipPartUri(New Uri("/", UriKind.RelativeOrAbsolute)))
' Sign() will prompt the user to select a Certificate to sign with.
Try
dsm.Sign(toSign)
Catch ex As CryptographicException
' If there are no certificates or the SmartCard manager is
' not running, catch the exception and show an error message.
MessageBox.Show("Cannot Sign" & vbLf & ex.Message, "No Digital Certificates Available", MessageBoxButton.OK, MessageBoxImage.Exclamation)
End Try
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
' end:SignAllParts()
Gilt für:
Sign(IEnumerable<Uri>, X509Certificate, IEnumerable<PackageRelationshipSelector>)
Signiert eine Liste der Paketteile und Paketbeziehungen mit einem bestimmten X.509-Zertifikat.
public:
System::IO::Packaging::PackageDigitalSignature ^ Sign(System::Collections::Generic::IEnumerable<Uri ^> ^ parts, System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate, System::Collections::Generic::IEnumerable<System::IO::Packaging::PackageRelationshipSelector ^> ^ relationshipSelectors);
public System.IO.Packaging.PackageDigitalSignature Sign(System.Collections.Generic.IEnumerable<Uri> parts, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Collections.Generic.IEnumerable<System.IO.Packaging.PackageRelationshipSelector> relationshipSelectors);
member this.Sign : seq<Uri> * System.Security.Cryptography.X509Certificates.X509Certificate * seq<System.IO.Packaging.PackageRelationshipSelector> -> System.IO.Packaging.PackageDigitalSignature
Public Function Sign (parts As IEnumerable(Of Uri), certificate As X509Certificate, relationshipSelectors As IEnumerable(Of PackageRelationshipSelector)) As PackageDigitalSignature
Parameter
- parts
- IEnumerable<Uri>
Die Liste der URIs (Uniform Resource Identifiers) für die PackagePart zu signierenden Objekte.
- certificate
- X509Certificate
Das X.509-Zertifikat, das verwendet werden soll, um die einzelnen angegebenen Teile und Beziehungen digital zu signieren.
- relationshipSelectors
- IEnumerable<PackageRelationshipSelector>
Die Liste der PackageRelationship zu signierenden Objekte.
Gibt zurück
Die digitale Signatur, die zum Signieren der in den parts Und-Listen relationshipSelectors angegebenen Elemente verwendet wird.
Ausnahmen
Weder noch partsrelationshipSelectors geben Sie objekte an, die signiert werden sollen.
Beispiele
Das folgende Beispiel zeigt, wie Sie eine Liste von Paketteilen digital signieren.
private static void SignAllParts(Package package)
{
if (package == null)
throw new ArgumentNullException("SignAllParts(package)");
// Create the DigitalSignature Manager
PackageDigitalSignatureManager dsm =
new PackageDigitalSignatureManager(package);
dsm.CertificateOption =
CertificateEmbeddingOption.InSignaturePart;
// Create a list of all the part URIs in the package to sign
// (GetParts() also includes PackageRelationship parts).
System.Collections.Generic.List<Uri> toSign =
new System.Collections.Generic.List<Uri>();
foreach (PackagePart packagePart in package.GetParts())
{
// Add all package parts to the list for signing.
toSign.Add(packagePart.Uri);
}
// Add the URI for SignatureOrigin PackageRelationship part.
// The SignatureOrigin relationship is created when Sign() is called.
// Signing the SignatureOrigin relationship disables counter-signatures.
toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin));
// Also sign the SignatureOrigin part.
toSign.Add(dsm.SignatureOrigin);
// Add the package relationship to the signature origin to be signed.
toSign.Add(PackUriHelper.GetRelationshipPartUri(new Uri("/", UriKind.RelativeOrAbsolute)));
// Sign() will prompt the user to select a Certificate to sign with.
try
{
dsm.Sign(toSign);
}
// If there are no certificates or the SmartCard manager is
// not running, catch the exception and show an error message.
catch (CryptographicException ex)
{
MessageBox.Show(
"Cannot Sign\n" + ex.Message,
"No Digital Certificates Available",
MessageBoxButton.OK,
MessageBoxImage.Exclamation);
}
}// end:SignAllParts()
Private Shared Sub SignAllParts(ByVal package As Package)
If package Is Nothing Then
Throw New ArgumentNullException("SignAllParts(package)")
End If
' Create the DigitalSignature Manager
Dim dsm As New PackageDigitalSignatureManager(package)
dsm.CertificateOption = CertificateEmbeddingOption.InSignaturePart
' Create a list of all the part URIs in the package to sign
' (GetParts() also includes PackageRelationship parts).
Dim toSign As New System.Collections.Generic.List(Of Uri)()
For Each packagePart As PackagePart In package.GetParts()
' Add all package parts to the list for signing.
toSign.Add(packagePart.Uri)
Next
' Add the URI for SignatureOrigin PackageRelationship part.
' The SignatureOrigin relationship is created when Sign() is called.
' Signing the SignatureOrigin relationship disables counter-signatures.
toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin))
' Also sign the SignatureOrigin part.
toSign.Add(dsm.SignatureOrigin)
' Add the package relationship to the signature origin to be signed.
toSign.Add(PackUriHelper.GetRelationshipPartUri(New Uri("/", UriKind.RelativeOrAbsolute)))
' Sign() will prompt the user to select a Certificate to sign with.
Try
dsm.Sign(toSign)
Catch ex As CryptographicException
' If there are no certificates or the SmartCard manager is
' not running, catch the exception and show an error message.
MessageBox.Show("Cannot Sign" & vbLf & ex.Message, "No Digital Certificates Available", MessageBoxButton.OK, MessageBoxImage.Exclamation)
End Try
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
' end:SignAllParts()
Hinweise
Zwischen parts und relationshipSelectors dort muss mindestens ein Element zum Signieren vorhanden sein.
Gilt für:
Sign(IEnumerable<Uri>, X509Certificate, IEnumerable<PackageRelationshipSelector>, String)
Signiert eine Liste der Paketteile und Paketbeziehungen mit einem bestimmten X.509-Zertifikat und -Bezeichner (ID).
public:
System::IO::Packaging::PackageDigitalSignature ^ Sign(System::Collections::Generic::IEnumerable<Uri ^> ^ parts, System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate, System::Collections::Generic::IEnumerable<System::IO::Packaging::PackageRelationshipSelector ^> ^ relationshipSelectors, System::String ^ signatureId);
public System.IO.Packaging.PackageDigitalSignature Sign(System.Collections.Generic.IEnumerable<Uri> parts, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Collections.Generic.IEnumerable<System.IO.Packaging.PackageRelationshipSelector> relationshipSelectors, string signatureId);
member this.Sign : seq<Uri> * System.Security.Cryptography.X509Certificates.X509Certificate * seq<System.IO.Packaging.PackageRelationshipSelector> * string -> System.IO.Packaging.PackageDigitalSignature
Public Function Sign (parts As IEnumerable(Of Uri), certificate As X509Certificate, relationshipSelectors As IEnumerable(Of PackageRelationshipSelector), signatureId As String) As PackageDigitalSignature
Parameter
- parts
- IEnumerable<Uri>
Die Liste der URIs (Uniform Resource Identifiers) für die PackagePart zu signierenden Objekte.
- certificate
- X509Certificate
Das X.509-Zertifikat, das verwendet werden soll, um die einzelnen angegebenen Teile und Beziehungen digital zu signieren.
- relationshipSelectors
- IEnumerable<PackageRelationshipSelector>
Die Liste der PackageRelationship zu signierenden Objekte.
- signatureId
- String
Eine Identifikationszeichenfolge, die der Signatur zugeordnet werden soll.
Gibt zurück
Die digitale Signatur, die zum Signieren der in den parts Und-Listen relationshipSelectors angegebenen Elemente verwendet wird.
Ausnahmen
Weder noch partsrelationshipSelectors geben Sie elemente an, die signiert werden sollen.
Beispiele
Das folgende Beispiel zeigt, wie Sie eine Liste von Paketteilen digital signieren.
private static void SignAllParts(Package package)
{
if (package == null)
throw new ArgumentNullException("SignAllParts(package)");
// Create the DigitalSignature Manager
PackageDigitalSignatureManager dsm =
new PackageDigitalSignatureManager(package);
dsm.CertificateOption =
CertificateEmbeddingOption.InSignaturePart;
// Create a list of all the part URIs in the package to sign
// (GetParts() also includes PackageRelationship parts).
System.Collections.Generic.List<Uri> toSign =
new System.Collections.Generic.List<Uri>();
foreach (PackagePart packagePart in package.GetParts())
{
// Add all package parts to the list for signing.
toSign.Add(packagePart.Uri);
}
// Add the URI for SignatureOrigin PackageRelationship part.
// The SignatureOrigin relationship is created when Sign() is called.
// Signing the SignatureOrigin relationship disables counter-signatures.
toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin));
// Also sign the SignatureOrigin part.
toSign.Add(dsm.SignatureOrigin);
// Add the package relationship to the signature origin to be signed.
toSign.Add(PackUriHelper.GetRelationshipPartUri(new Uri("/", UriKind.RelativeOrAbsolute)));
// Sign() will prompt the user to select a Certificate to sign with.
try
{
dsm.Sign(toSign);
}
// If there are no certificates or the SmartCard manager is
// not running, catch the exception and show an error message.
catch (CryptographicException ex)
{
MessageBox.Show(
"Cannot Sign\n" + ex.Message,
"No Digital Certificates Available",
MessageBoxButton.OK,
MessageBoxImage.Exclamation);
}
}// end:SignAllParts()
Private Shared Sub SignAllParts(ByVal package As Package)
If package Is Nothing Then
Throw New ArgumentNullException("SignAllParts(package)")
End If
' Create the DigitalSignature Manager
Dim dsm As New PackageDigitalSignatureManager(package)
dsm.CertificateOption = CertificateEmbeddingOption.InSignaturePart
' Create a list of all the part URIs in the package to sign
' (GetParts() also includes PackageRelationship parts).
Dim toSign As New System.Collections.Generic.List(Of Uri)()
For Each packagePart As PackagePart In package.GetParts()
' Add all package parts to the list for signing.
toSign.Add(packagePart.Uri)
Next
' Add the URI for SignatureOrigin PackageRelationship part.
' The SignatureOrigin relationship is created when Sign() is called.
' Signing the SignatureOrigin relationship disables counter-signatures.
toSign.Add(PackUriHelper.GetRelationshipPartUri(dsm.SignatureOrigin))
' Also sign the SignatureOrigin part.
toSign.Add(dsm.SignatureOrigin)
' Add the package relationship to the signature origin to be signed.
toSign.Add(PackUriHelper.GetRelationshipPartUri(New Uri("/", UriKind.RelativeOrAbsolute)))
' Sign() will prompt the user to select a Certificate to sign with.
Try
dsm.Sign(toSign)
Catch ex As CryptographicException
' If there are no certificates or the SmartCard manager is
' not running, catch the exception and show an error message.
MessageBox.Show("Cannot Sign" & vbLf & ex.Message, "No Digital Certificates Available", MessageBoxButton.OK, MessageBoxImage.Exclamation)
End Try
End Sub
Private Shared Function InlineAssignHelper(Of T)(ByRef target As T, ByVal value As T) As T
target = value
Return value
End Function
' end:SignAllParts()
Hinweise
Die parts Liste kann leer sein oder null mindestens relationshipSelectors einen Eintrag enthalten.
Die relationshipSelectors Liste kann leer sein oder null mindestens parts einen Eintrag enthalten.
Zwischen der parts Liste und relationshipSelectors dem Signieren muss mindestens ein Element vorhanden sein.
Gilt für:
Sign(IEnumerable<Uri>, X509Certificate, IEnumerable<PackageRelationshipSelector>, String, IEnumerable<DataObject>, IEnumerable<Reference>)
Signiert eine Liste von Paketteilen, Paketbeziehungen oder benutzerdefinierten Objekten mit einem angegebenen X.509-Zertifikat- und Signaturbezeichner (ID).
public:
System::IO::Packaging::PackageDigitalSignature ^ Sign(System::Collections::Generic::IEnumerable<Uri ^> ^ parts, System::Security::Cryptography::X509Certificates::X509Certificate ^ certificate, System::Collections::Generic::IEnumerable<System::IO::Packaging::PackageRelationshipSelector ^> ^ relationshipSelectors, System::String ^ signatureId, System::Collections::Generic::IEnumerable<System::Security::Cryptography::Xml::DataObject ^> ^ signatureObjects, System::Collections::Generic::IEnumerable<System::Security::Cryptography::Xml::Reference ^> ^ objectReferences);
[System.Security.SecurityCritical]
public System.IO.Packaging.PackageDigitalSignature Sign(System.Collections.Generic.IEnumerable<Uri> parts, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Collections.Generic.IEnumerable<System.IO.Packaging.PackageRelationshipSelector> relationshipSelectors, string signatureId, System.Collections.Generic.IEnumerable<System.Security.Cryptography.Xml.DataObject> signatureObjects, System.Collections.Generic.IEnumerable<System.Security.Cryptography.Xml.Reference> objectReferences);
public System.IO.Packaging.PackageDigitalSignature Sign(System.Collections.Generic.IEnumerable<Uri> parts, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Collections.Generic.IEnumerable<System.IO.Packaging.PackageRelationshipSelector> relationshipSelectors, string signatureId, System.Collections.Generic.IEnumerable<System.Security.Cryptography.Xml.DataObject> signatureObjects, System.Collections.Generic.IEnumerable<System.Security.Cryptography.Xml.Reference> objectReferences);
[<System.Security.SecurityCritical>]
member this.Sign : seq<Uri> * System.Security.Cryptography.X509Certificates.X509Certificate * seq<System.IO.Packaging.PackageRelationshipSelector> * string * seq<System.Security.Cryptography.Xml.DataObject> * seq<System.Security.Cryptography.Xml.Reference> -> System.IO.Packaging.PackageDigitalSignature
member this.Sign : seq<Uri> * System.Security.Cryptography.X509Certificates.X509Certificate * seq<System.IO.Packaging.PackageRelationshipSelector> * string * seq<System.Security.Cryptography.Xml.DataObject> * seq<System.Security.Cryptography.Xml.Reference> -> System.IO.Packaging.PackageDigitalSignature
Public Function Sign (parts As IEnumerable(Of Uri), certificate As X509Certificate, relationshipSelectors As IEnumerable(Of PackageRelationshipSelector), signatureId As String, signatureObjects As IEnumerable(Of DataObject), objectReferences As IEnumerable(Of Reference)) As PackageDigitalSignature
Parameter
- parts
- IEnumerable<Uri>
Die Liste der URIs (Uniform Resource Identifiers) für die PackagePart zu signierenden Objekte.
- certificate
- X509Certificate
Das X.509-Zertifikat, das verwendet werden soll, um die einzelnen angegebenen Teile und Beziehungen digital zu signieren.
- relationshipSelectors
- IEnumerable<PackageRelationshipSelector>
Die Liste der PackageRelationship zu signierenden Objekte.
- signatureId
- String
Eine Identifikationszeichenfolge, die der Signatur zugeordnet werden soll.
- signatureObjects
- IEnumerable<DataObject>
Eine Liste der zu signierenden benutzerdefinierten Datenobjekte.
- objectReferences
- IEnumerable<Reference>
Eine Liste von Verweisen auf benutzerdefinierte Objekte, die signiert werden sollen.
Gibt zurück
Die digitale Signatur, die zum Signieren der in den parts Und-Listen relationshipSelectors angegebenen Elemente verwendet wird.
- Attribute
Ausnahmen
Weder parts, noch relationshipSelectorssignatureObjectsobjectReferences geben Sie elemente an, die signiert werden sollen.
Ein ContentType Teil, der signiert wird, verweist auf ein leeres oder nullnicht definiertes TransformMappingElement.
signatureId ist keine null gültige XML-Schema-ID (z. B. beginnt mit einer führenden numerischen Ziffer).
Hinweise
Es muss mindestens ein Element vorhanden sein, um sich anzumeldenparts, oder signatureObjectsrelationshipSelectorsobjectReferences.
Hinweis
Die Begriffe Object, Manifest, Reference, SignatureProperties, und Transform in den folgenden beiden Anmerkungen beziehen sich auf Elementtypen und Tags, die durch die W3C-XML-Signature Syntax- und Verarbeitungsspezifikation definiert sind, siehe https://www.w3.org/TR/xmldsig-core/.
Diese und andere Sign Methodenüberladungen verwenden das aktuelle TransformMapping Wörterbuch, das eine Transform Anwendung basierend auf dem Paketteil ContentTypedefiniert. Die Spezifikation der Microsoft Open Packaging Conventions (OPC) lässt derzeit nur zwei gültige Transform Algorithmen zu: C14 und C14N. Der W3C-XML-Signature Syntax- und Verarbeitungsstandard lässt keine leeren Manifest Tags zu. Außerdem erfordert die Spezifikation der Open Packaging-Konventionen ein Package-spezifisches Object Tag, das sowohl als auch ManifestSignatureProperties Tags enthält. Jedes Manifest Tag enthält außerdem mindestens ein Reference Tag. Diese Tags erfordern, dass jedes Signaturzeichen mindestens ein PackagePart Signaturzeichen (nicht leere Teile-Tag) oder PackageRelationship (nicht leerrelationshipSelectors) auch dann erforderlich ist, wenn die Signatur nur zum Signieren oder objectReferencesSignieren signatureObjects erforderlich ist.
Diese Sign Methode ignoriert die eigenschaft, die DigestMethod jedem Reference definierten Element objectReferenceszugeordnet ist.
Diese Sign Überladung bietet Unterstützung für die Generierung von XML-Signaturen, die benutzerdefinierte Object Tags erfordern. Damit jedes bereitgestellte Object Tag signiert wird, muss ein entsprechendes Reference Tag mit einem URI (Uniform Resource Identifier) bereitgestellt werden, der das Tag in der Object lokalen Fragmentsyntax angibt. Wenn das Object Tag beispielsweise über eine ID von "myObject" verfügt, lautet der URI im Reference Tag "#myObject". Für nicht signierte Objekte ist keine Reference Erforderlich.