/// <summary> /// Verify document with digital signature with applying specific options /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Advanced Usage] # VerifyDigitalAdvanced : Verify document with digital signature with applying specific options\n"); // The path to the documents directory. string filePath = Constants.SAMPLE_PDF_SIGNED_DIGITAL; using (Signature signature = new Signature(filePath)) { DigitalVerifyOptions options = new DigitalVerifyOptions() { // specify special search criteria Comments = "Approved", // specify date range period of signature SignDateTimeFrom = new DateTime(year: 2020, month: 01, day: 01), SignDateTimeTo = new DateTime(year: 2020, month: 12, day: 31) }; // verify document signatures VerificationResult result = signature.Verify(options); if (result.IsValid) { Console.WriteLine("\nDocument was verified successfully!"); } else { Helper.WriteError("\nDocument failed verification process."); } } }
/// <summary> /// Verify document with digital signature /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Basic Usage] # VerifyDigital : Verify document with digital signature \n"); // The path to the documents directory. string filePath = Constants.SAMPLE_SIGNED_MULTI; using (Signature signature = new Signature(filePath)) { DigitalVerifyOptions options = new DigitalVerifyOptions(Constants.CertificatePfx) { Contact = "Mr.Smith", Password = "******" }; // verify document signatures VerificationResult result = signature.Verify(options); if (result.IsValid) { Console.WriteLine($"\nDocument {filePath} was verified successfully!"); } else { Helper.WriteError($"\nDocument {filePath} failed verification process."); } } }
/// <summary> /// Verify document with exception handling /// </summary> public static void Run() { Console.WriteLine("\n--------------------------------------------------------------------------------------------------------------------"); Console.WriteLine("[Example Advanced Usage] # VerifyWithExceptionHandling : Verify document with exception handling\n"); // The path to the documents directory. string filePath = Constants.SAMPLE_PDF; try { using (Signature signature = new Signature(filePath)) { DigitalVerifyOptions options = new DigitalVerifyOptions() { CertificateFilePath = "dummy.pfx", // skip password specification // Password = "******" }; // sign document to file VerificationResult result = signature.Verify(options); } } catch (GroupDocsSignatureException ex) { Console.WriteLine("GroupDocs Signature Exception: " + ex.Message); } catch (Exception ex) { Console.WriteLine("System Exception: " + ex.Message); } }
/// <summary> /// Verify document with Text signature /// </summary> public static void Run() { // The path to the documents directory. string filePath = Constants.SAMPLE_SIGNED_MULTI; using (Signature signature = new Signature(filePath)) { TextVerifyOptions textVerifyOptions = new TextVerifyOptions() { AllPages = true, // this value is set by default SignatureImplementation = TextSignatureImplementation.Native, Text = "Text signature", MatchType = TextMatchType.Contains }; BarcodeVerifyOptions barcVerifyOptions = new BarcodeVerifyOptions() { AllPages = true, // this value is set by default Text = "12345", MatchType = TextMatchType.Contains }; QrCodeVerifyOptions qrcdVerifyOptions = new QrCodeVerifyOptions() { AllPages = true, // this value is set by default Text = "John", MatchType = TextMatchType.Contains }; DigitalVerifyOptions digtVerifyOptions = new DigitalVerifyOptions(Constants.CertificatePfx) { SignDateTimeFrom = new DateTime(year: 2020, month: 01, day: 01), SignDateTimeTo = new DateTime(year: 2020, month: 12, day: 31), Password = "******" }; // verify document signatures List <VerifyOptions> listOptions = new List <VerifyOptions>(); listOptions.Add(textVerifyOptions); listOptions.Add(barcVerifyOptions); listOptions.Add(qrcdVerifyOptions); listOptions.Add(digtVerifyOptions); VerificationResult result = signature.Verify(listOptions); if (result.IsValid) { Console.WriteLine("\nDocument was verified successfully!"); } else { Console.WriteLine("\nDocument failed verification process."); } } }