PackageDigitalSignatureManager.VerifySignatures Method (Boolean)


Verifies the signatures on all signed parts within the package.

Namespace:   System.IO.Packaging
Assembly:  WindowsBase (in WindowsBase.dll)

public VerifyResult VerifySignatures(
	bool exitOnFailure


Type: System.Boolean

true to exit on first failure; otherwise, false to continue and check all signatures.

Return Value

Type: System.IO.Packaging.VerifyResult

Success (value 0) if all signatures are verified successfully; otherwise, an enumeration that identifies the error.

This method verifies only the digital signatures; it does not verify the related X.509 certificates. The VerifyCertificate method can be used to verify the X.509 certificates.

The following example shows how to use this method to validate all signed parts within a package. For the complete sample, see Creating a Package with a Digital Signature Sample.

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

.NET Framework
Available since 3.0
Return to top