DocumentSigner.Validate(String, SignatureValidationOptions) Method
Validates a signature in the specified file with the specified options.
Namespace: DevExpress.Office.DigitalSignatures
Assembly: DevExpress.Docs.v24.1.dll
NuGet Package: DevExpress.Document.Processor
Declaration
public PackageSignatureValidation Validate(
string inputFileName,
SignatureValidationOptions options
)
Parameters
Name | Type | Description |
---|---|---|
inputFileName | String | A name of a file with a signature (including the full path). |
options | SignatureValidationOptions | An object that contains validation options. |
Returns
Type | Description |
---|---|
PackageSignatureValidation | An object that contains validation information. |
Remarks
Validation Options
The SignatureValidationOptions object allows you to specify signature validation options. Use the SignatureValidationOptions.ValidationFlags property to exclude validation steps.
private static void ValidateSignature(string path)
{
DocumentSigner validator = new DocumentSigner();
//Specify validation options
//In this example, certificate validation is skipped
SignatureValidationOptions validationOptions = new SignatureValidationOptions();
validationOptions.ValidationFlags = ~ValidationFlags.ValidateSignatureCertificate & ~ValidationFlags.ValidateTimestampCertificate;
//Validate the signature:
PackageSignatureValidation signatureValidation = validator.Validate(path, validationOptions);
AnalyzeValidationResult(signatureValidation);
}
Validation Process
The Validate method returns the PackageSignatureValidation instance that contains validation information. Check the PackageSignatureValidation.Result and PackageSignatureValidation.ResultMessage properties to determine whether the signature is valid.
Note
Make sure that the signature certificate is registered on your machine. Otherwise, the signature is invalid.
If the document is not signed, the PackageSignatureValidation.Result property returns SignaturesNotFound.
If the document to be validated is encrypted, specify the SignatureValidationOptions.DecryptionPassword property to decrypt the document. Otherwise, the Result property returns PackageSignatureValidationResult.PackageOpenFailed.
If the PackageSignatureValidation.Result property returns Invalid or PartiallyValid, check the PackageSignatureValidation.Items property to obtain a list of items with validation information. The number of SignatureValidationInfo objects in the list is equal to the number of signatures.
The table below lists API used to obtain information:
Property | Description |
---|---|
SignatureValidationInfo.PassedChecks | Returns verification types the signature passed. |
SignatureValidationInfo.PassedCheckDetails | Obtains information about passed verifications. |
SignatureValidationInfo.FailedChecks | Returns verification types the signature did not pass. |
SignatureValidationInfo.FailedCheckDetails | Retrieves information about failed verifications. |
SignatureValidationInfo.CheckDetails | Gets information about all verifications. |
The code sample below analyzes the validation result and shows information in the console:
private static void AnalyzeValidationResult(PackageSignatureValidation signatureValidation)
{
string validationMessage = signatureValidation.ResultMessage;
//Check validation result and show information in the console:
switch (signatureValidation.Result)
{
case PackageSignatureValidationResult.Valid:
Console.WriteLine(validationMessage); Console.ReadKey();
Process.Start(output);
break;
case PackageSignatureValidationResult.SignaturesNotFound:
Console.WriteLine(validationMessage);
break;
case PackageSignatureValidationResult.Invalid:
case PackageSignatureValidationResult.PartiallyValid:
var failedCheckDetails = signatureValidation.Items[0].FailedCheckDetails;
Console.WriteLine(validationMessage);
int i = 1;
foreach (SignatureCheckResult checkResult in failedCheckDetails)
{
Console.WriteLine(String.Format("Validation details {0}: \r\n" +
"{1} failed, Info: {2} \r\n", i, checkResult.CheckType, checkResult.Info));
i++;
}
Console.ReadKey();
break;
}
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the Validate(String, SignatureValidationOptions) method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.