PDF digital signature validation

The following example shows how to validate all signatures in the PDF document, in your C# or VB.NET application using the GemBox.Pdf library.

Upload your file (Drag file here)
using GemBox.Pdf;
using GemBox.Pdf.Forms;
using System;

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 GemBox.Pdf
Imports GemBox.Pdf.Forms
Imports System

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
PDF signature validation status acquired using GemBox.Pdf
Screenshot of PDF signature validation status acquired using GemBox.Pdf

General 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 , you can validate that the PDF document has not been modified since the signature was applied in your C#However, GemBox.Pdf currently doesn't check the validity of the signer's identity. 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