PDF digital signature validation in C# and VB.NET

PDF digital signature validation primarily checks that:

  • The document has not been modified since the signature was applied.
  • The signer's identity is valid.

With GemBox.Pdf, you can validate that the PDF document has not been modified since the signature was applied in your C# or VB.NET application.

Before running the following example on your machine, please read the Dependencies notes.

The following example shows how to validate all signatures in the PDF document.

PDF signature validation status acquired using GemBox.Pdf
Screenshot of PDF signature validation status acquired using GemBox.Pdf
Upload your file (Drag file here)
using System;
using GemBox.Pdf;
using GemBox.Pdf.Forms;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (var document = PdfDocument.Load("%InputFileName%"))
        {
            foreach (var field in document.Form.Fields)
                if (field.FieldType == PdfFieldType.Signature)
                {
                    var signatureField = (PdfSignatureField)field;

                    var signature = signatureField.Value;

                    if (signature != null)
                    {
                        var signatureValidationResult = signature.Validate();

                        if (signatureValidationResult.IsValid)
                        {
                            Console.Write("Signature '{0}' is VALID, signed by '{1}'. ", signatureField.Name, signature.Content.SignerCertificate.SubjectCommonName);
                            Console.WriteLine("The document has not been modified since this signature was applied.");
                        }
                        else
                        {
                            Console.Write("Signature '{0}' is INVALID. ", signatureField.Name);
                            Console.WriteLine("The document has been altered or corrupted since the signature was applied.");
                        }
                    }
                }
        }
    }
}
Imports System
Imports GemBox.Pdf
Imports GemBox.Pdf.Forms

Module Program

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Using document = PdfDocument.Load("%InputFileName%")

            For Each field In document.Form.Fields
                If field.FieldType = PdfFieldType.Signature Then

                    Dim signatureField = CType(field, PdfSignatureField)

                    Dim signature = signatureField.Value

                    If signature IsNot Nothing Then

                        Dim signatureValidationResult = signature.Validate()

                        If signatureValidationResult.IsValid Then

                            Console.Write("Signature '{0}' is VALID, signed by '{1}'. ", signatureField.Name, signature.Content.SignerCertificate.SubjectCommonName)
                            Console.WriteLine("The document has not been modified since this signature was applied.")

                        Else

                            Console.Write("Signature '{0}' is INVALID. ", signatureField.Name)
                            Console.WriteLine("The document has been altered or corrupted since the signature was applied.")
                        End If
                    End If
                End If
            Next
        End Using
    End Sub
End Module

Note that the validity of the signer's identity is currently not checked. This feature will be implemented in future versions of GemBox.Pdf, based on user feedback.

Dependencies notes

Except GemBox.Pdf, your project must reference the following NuGet packages:

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Pdf yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.