Products Technologies Demo Docs Blog Support Company
TX Text Control 34.0 has been released - Learn more

Validate Digital Signatures and the Integrity of PDF Documents in C# .NET

Learn how to validate digital signatures and the integrity of PDF documents using the PDF Validation component from TX Text Control in C# .NET. Ensure the authenticity and compliance of your documents.

Validate Digital Signatures and the Integrity of PDF Documents in C# .NET

PDFs are the final, authoritative versions of contracts, invoices, reports, and official records. These documents are archived and routed through workflows, and they are often treated as legal evidence.

That only works if you can trust two things:

  • Who signed the document.
  • The document has not been altered since it was signed.

This is where digital signatures and systematic validation are useful.

What a PDF Digital Signature actually is

A digital signature is a cryptographic mechanism that verifies the authenticity and integrity of a PDF document. Using a combination of public key infrastructure (PKI) and hashing algorithms, it creates a unique signature tied to both the document's content and the signer's identity.

When a Signed PDF is no longer valid

A signed PDF document may become invalid if any part of the document is modified after signing. This is because the hash value will no longer match the original signature. An integrity check will fail, and the signature must be reported as invalid.

With the TX Text Control PDF Validation library TXTextControl.PDF.Validation, you can validate the digital signatures and integrity of PDF documents generated with TX Text Control.

Validating Digital Signatures

The PDF Validation component can validate digital signatures embedded in PDF documents. Digital signatures ensure the authenticity and integrity of a document. During the validation process, the component checks if the signature is valid and if the document has been altered since it was signed. It also returns the certificate information.

Creating the Application

First, create a new .NET console application and install the TXTextControl.PDF.Validation NuGet package.

Make sure that you downloaded the latest version of Visual Studio 2022 that comes with the .NET 8 SDK.

  1. In Visual Studio 2022, create a new project by choosing Create a new project.

  2. Select Console App as the project template and confirm with Next.

  3. Enter a project name and choose a location to save the project. Confirm with Next.

  4. Choose .NET 8.0 (Long Term Support) as the Framework.

    Creating the .NET 8 project

Adding the NuGet Packages

  1. In the Solution Explorer, select your created project and choose Manage NuGet Packages... from the Project main menu. Select nuget.org as the Package source Enable the Include prerelease checkbox.

    Install the following package:

    • TXTextControl.PDF.Validation

    ASP.NET Core Web Application

Validating a PDF Document

  1. Find the Program.cs file in the Solution Explorer and replace the code with the following code snippet:

    using TXTextControl.PDF.Validation;
    
    const string DefaultFileName = "documents/result.pdf"; // adjust path if needed
    
    // first non-flag is the filename
    string? fileArg = args.FirstOrDefault(a => !a.StartsWith("--", StringComparison.Ordinal));
    
    string file = fileArg ?? Path.Combine(AppContext.BaseDirectory, DefaultFileName);
    
    if (!File.Exists(file))
    {
        Console.Error.WriteLine($"File not found: {file}\nUsage: pdfua <file.pdf>");
        Environment.Exit(2);
    }
    
    try
    {
        var report = PdfUaValidator.Validate(file);
    
        var sig = report?.Signature;
        if (sig is null)
        {
            Console.WriteLine("No signature found in the report.");
            return;
        }
    
        var hasSignature = sig.HasSignature;
        var signatureBytesIntact = sig.SignatureBytesIntact;
        var failureReason = sig.FailureReason;
        var signerSubject = sig.SignerSubject;
        var coversWholeDocument = sig.CoversWholeDocument;
        var probablyModifiedAfterSigning = sig.ProbablyModifiedAfterSigning;
        var signingTime = sig.SigningTime;
    
    
        Console.WriteLine($"Has signature: {hasSignature}");
        Console.WriteLine($"Signature bytes intact: {signatureBytesIntact}");
        Console.WriteLine($"Failure reason: {failureReason}");
        Console.WriteLine($"Signer subject: {signerSubject}");
        Console.WriteLine($"Covers whole document: {coversWholeDocument}");
        Console.WriteLine($"Probably modified after signing: {probablyModifiedAfterSigning}");
        Console.WriteLine($"Signing time: {signingTime}");
    
    }
    catch (Exception ex)
    {
        Console.Error.WriteLine("Analysis failed:");
        Console.Error.WriteLine(ex);
        Environment.Exit(2);
    }
  2. Create a folder named documents in the project directory and add a signed PDF document named generated with TX Text Control as result.pdf. Set the file's Copy to Output Directory property to Copy if newer.

Starting the Application

Run the application. The console window will display the validation results, including any detected issues.

Document name: result.pdf
Document title: PDF Title
Has signature: True
Signature bytes intact: True
Failure reason:
Signer subject: CN=MyTXCert
Covers whole document: True
Probably modified after signing: False
Signing time: 11/12/2025 4:37:58 PM +00:00

In the sample code above, we load a valid PDF document with a digital signature, ensuring that the document has not been altered since signing. Now, let's modify the document to see how the validation process detects changes.

The following screenshot shows the document's integrity in Acrobat Reader:

Valid PDF Document

Modifying the PDF Document

First, we open the PDF document in a text editor and modify some text or binary data. Then, after saving the changes, we run the validation application again. In our sample, we simply change the Producer entry in the PDF metadata from TX Text Control 34 to a different value.

<<
/Title (þÿ P D F   T i t l e)
/Producer (TX Text Control 44)
/CreationDate (D:20251020122432Z)
>>

The console window will now indicate that the document has been modified and that the digital signature is invalid.

Document name: result.pdf
Document title: PDF Title
Has signature: True
Signature bytes intact: False
Failure reason: Cryptographic verification failed: The hash value is not correct.
Signer subject:
Covers whole document: False
Probably modified after signing: True
Signing time:

The following screenshot shows the document's integrity in Acrobat Reader after modification:

Invalid PDF Document

Integrating PDF Validation into Your Applications

The TX Text Control PDF Validation component can be seamlessly integrated into various types of applications, including web and desktop applications, as well as backend services. Incorporating PDF validation into your document workflows ensures the authenticity and integrity of your PDF documents throughout their lifecycle.

Conclusion

Validating digital signatures and the integrity of PDF documents is essential to maintaining trust and compliance in document management. The TX Text Control PDF Validation component is a robust solution for verifying digital signatures and ensuring that PDF documents remain unaltered. Integrating this functionality into your applications enhances the security and reliability of your document workflows.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETASP.NET CorePDF

Validate PDF/UA Documents and Verify Electronic Signatures in C# .NET

The new TXTextControl.PDF.Validation NuGet package enables you to validate PDF/UA documents and verify digital signatures directly in your code without relying on third-party tools or external…


ASP.NETAIASP.NET Core

Automating PDF/UA Accessibility with AI: Describing DOCX Documents Using TX…

This article shows how to use TX Text Control together with the OpenAI API to automatically add descriptive texts (alt text and labels) to images, links, and tables in a DOCX. The resulting…


ASP.NETASP.NET CorePDF

Why PDF/UA and PDF/A-3a Matter: Accessibility, Archiving, and Legal Compliance

It is more important than ever to ensure that documents are accessible, archivable, and legally compliant. PDF/UA and PDF/A-3a are two effective standards for addressing these needs. This article…


ASP.NETASP.NET CoreC#

How To Choose the Right C# PDF Generation Library: Developer Checklist

To make your choice easy, this guide provides a systematic evaluation framework for two library categories: basic and enterprise PDF libraries. It covers matching features to use cases, evaluating…


ActiveXASP.NETWindows Forms

Introducing TX Text Control 34.0: Your Next Leap in Document Processing.

We are happy to announce the release of TX Text Control 34.0. This version is packed with new features and enhancements that will elevate your document processing experience. This version…