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.

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 the 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 the 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.

See also


Next steps

GemBox.Pdf is a .NET component that enables developers to read, merge and split PDF files or execute low-level object manipulations from .NET applications in a simple and efficient way.

Download Buy