PackageDigitalSignatureManager.VerifySignatures(Boolean) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
確認封裝內所有已簽署組件上的簽章。
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
參數
- exitOnFailure
- Boolean
true
表示在第一次失敗時結束;否則,false
表示繼續並檢查所有簽章。
傳回
如果已順利驗證所有簽章,則為 Success (值 0);否則為識別錯誤的列舉。
範例
下列範例示範如何使用此方法來驗證封裝內的所有已簽署元件。
// ------------------------ 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()
備註
此方法只會驗證數字簽名;它不會驗證相關的 X.509 憑證。 方法 VerifyCertificate 可用來驗證 X.509 憑證。