PackageDigitalSignatureManager.IsSigned 属性

定义

获取一个值,该值指示包是否包含任何签名。

public:
 property bool IsSigned { bool get(); };
public bool IsSigned { get; }
member this.IsSigned : bool
Public ReadOnly Property IsSigned As Boolean

属性值

如果包中包含签名,则为 true,否则为 false

示例

以下示例演示如何使用 IsSigned 属性来确定包是否包含数字签名。

// ------------------------ ValidateSignatures ------------------------
/// <summary>
///   Validates all the digital signatures of a given package.</summary>
/// <param name="package">
///   The package for validating digital signatures.</param>
/// <returns>
///   true if all digital signatures are valid; otherwise false if the
///   package is unsigned or any of the signatures are invalid.</returns>
private static bool ValidateSignatures(Package package)
{
    if (package == null)
        throw new ArgumentNullException("ValidateSignatures(package)");

    // Create a PackageDigitalSignatureManager for the given Package.
    PackageDigitalSignatureManager dsm =
        new PackageDigitalSignatureManager(package);

    // Check to see if the package contains any signatures.
    if (!dsm.IsSigned)
        return false;   // The package is not signed.

    // Verify that all signatures are valid.
    VerifyResult result = dsm.VerifySignatures(false);
    if (result != VerifyResult.Success)
        return false;   // One or more digital signatures are invalid.

    // else if (result == VerifyResult.Success)
    return true;        // All signatures are valid.
}// end:ValidateSignatures()
' ------------------------ ValidateSignatures ------------------------
''' <summary>
''' Validates all the digital signatures of a given package.</summary>
''' <param name="package">
''' The package for validating digital signatures.</param>
''' <returns>
''' true if all digital signatures are valid; otherwise false if the
''' package is unsigned or any of the signatures are invalid.</returns>
Private Shared Function ValidateSignatures(ByVal package As Package) As Boolean
    If package Is Nothing Then
        Throw New ArgumentNullException("ValidateSignatures(package)")
    End If

    ' Create a PackageDigitalSignatureManager for the given Package.
    Dim dsm As New PackageDigitalSignatureManager(package)

    ' Check to see if the package contains any signatures.
    If Not dsm.IsSigned Then
        Return False
    End If
    ' The package is not signed.
    ' Verify that all signatures are valid.
    Dim result As VerifyResult = dsm.VerifySignatures(False)
    If result <> VerifyResult.Success Then
        Return False
    End If
    ' One or more digital signatures are invalid.
    ' else if (result == VerifyResult.Success)
    ' All signatures are valid.
    Return True
End Function
' end:ValidateSignatures()

注解

属性 IsSigned 不执行签名验证。 如果签名存在并且 IsSignedtrue,则一个或多个签名可能无效。 调用 VerifySignatures 以确认签名有效且未更改。

适用于

另请参阅