Bagikan melalui


PackageDigitalSignatureManager.VerifySignatures(Boolean) Metode

Definisi

Memverifikasi tanda tangan pada semua bagian yang ditandatangani dalam paket.

public:
 System::IO::Packaging::VerifyResult VerifySignatures(bool exitOnFailure);
public System.IO.Packaging.VerifyResult VerifySignatures (bool exitOnFailure);
member this.VerifySignatures : bool -> System.IO.Packaging.VerifyResult
Public Function VerifySignatures (exitOnFailure As Boolean) As VerifyResult

Parameter

exitOnFailure
Boolean

true untuk keluar pada kegagalan pertama; jika tidak, false untuk melanjutkan dan memeriksa semua tanda tangan.

Mengembalikan

Success (nilai 0) jika semua tanda tangan berhasil diverifikasi; jika tidak, enumerasi yang mengidentifikasi kesalahan.

Contoh

Contoh berikut menunjukkan cara menggunakan metode ini untuk memvalidasi semua bagian yang ditandatangani dalam paket.

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

Keterangan

Metode ini hanya memverifikasi tanda tangan digital; tidak memverifikasi sertifikat X.509 terkait. Metode VerifyCertificate ini dapat digunakan untuk memverifikasi sertifikat X.509.

Berlaku untuk

Lihat juga