CertificateEmbeddingOption Enumeração
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Especifica o local onde o certificado X.509 utilizado na assinatura é armazenado.
public enum class CertificateEmbeddingOption
public enum CertificateEmbeddingOption
type CertificateEmbeddingOption =
Public Enum CertificateEmbeddingOption
- Herança
Campos
| Name | Valor | Description |
|---|---|---|
| InCertificatePart | 0 | O certificado está embutido no seu próprio PackagePart. |
| InSignaturePart | 1 | O certificado está incorporado no SignaturePart que é criado para a assinatura que está a ser adicionada. |
| NotEmbedded | 2 | O certificado não está incorporado no pacote. |
Exemplos
O exemplo seguinte mostra como usar CertificateEmbeddingOption para definir a PackageDigitalSignatureManager.CertificateOption propriedade.
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()
Observações
Se o certificado estiver NotEmbedded no pacote, uma aplicação que verifique assinaturas deve fornecer uma cópia do certificado para verificar as assinaturas assinadas por ele.
InSignaturePart adiciona dois elementos informativos, <KeyName> e <KeyValue>, como parte do KeyInfo campo da assinatura digital armazenada. Os <KeyName> elementos e <KeyValue> não são processados como parte da validação de assinaturas e, por isso, não são seguros contra modificações. As candidaturas não devem fazer qualquer suposição quanto à validade destes dois elementos. Para evitar modificações não detetadas e possível confusão, as aplicações devem usar a InCertificatePart opção em vez de InSignaturePart. A InCertificatePart opção não fornece nem expõe nenhum <KeyName> dos <KeyValue>dois .