How to Digitally Sign and Verify PDF Documents in C# (PDF 2.0 Update)
Tags: csharp, dotnet, productivity
Published: 2019-10-30 11:34:53

---
title: How to Digitally Sign and Verify PDF Documents in C# (PDF 2.0 Update)
published: true
date: 2019-10-22 11:00:10 UTC
tags: csharp, dotnet, productivity
canonical_url: https://www.syncfusion.com/blogs/post/digitally-sign-and-verify-pdf-documents-csharp.aspx
cover_image: https://thepracticaldev.s3.amazonaws.com/i/e45bk83fkfw2a18cbblp.jpg
---

Many professional sectors and industries are using PDF file format to view, print, and share all kinds of information.

Imagine a PDF document that has information with legal value. Such a document may contain important information about rights and obligations, in which case you need to ensure its authenticity and integrity. The solution is adding a digital signature in your PDF document.

The [Syncfusion PDF Library](https://www.syncfusion.com/pdf-framework/net/pdf-library) provides support to create and validate PDF digital signatures using C# or VB.NET.

In this blog, I am going to show you how to create and validate a PDF digital signature using the Syncfusion PDF Library that will help you and your organization to achieve the following benefits:

- Digitally sign a PDF that is legally valid across the world.
- Add extra security to your signatures.
- Bulk sign.
- Eliminate physical signing and improve time management.
- Improve cost effectiveness.

Digital signatures created with Syncfusion PDF Library comply with the data protection standards specified by the **European Telecommunications Standards Institute**  (ETSI) and the **PDF Advanced Electronic Signature** (PAdES) standard.

As per the PDF 2.0 specification, Syncfusion PDF Library creates digital signatures based on the CMS (cryptographic message syntax) and CAdES (CMS advanced electronic signatures).

Please refer to the following table for more information about various supported cryptographic standards and their equivalent PAdES parts.

<table>
<tbody>
<tr>
<td width="312"><strong>Cryptographic standard</strong></td>
<td width="312"><strong>PAdES parts</strong></td>
</tr>
<tr>
<td width="312">CMS</td>
<td width="312">Part 2 of the PAdES</td>
</tr>
<tr>
<td width="312">CAdES</td>
<td width="312">Part 3 of the PAdES</td>
</tr>
<tr>
<td width="312">CAdES with time stamp and LTV</td>
<td width="312">Part 4 of the PAdES</td>
</tr>
</tbody>
</table>

The complete life cycle from digitally signing a PDF to validating the signature is explained in the following topics in this post:

- Digitally sign a PDF file.
- PDF digital signatures with custom appearances.
- Digital signatures with CAdES and different hashing algorithms.
- Adding multiple digital signatures in a single PDF document.
- Digitally sign a PDF document using Windows certificate store.
- Digitally sign a PDF document with an external signature.
- Digitally sign existing signature field in a PDF document.
- Add a timestamp to a digital signature.
- Retrieving digital signature information from a PDF document.
- Remove existing digital signatures from a PDF document.
- Validate a PDF digital signature.

## Digitally sign a PDF file

To create a PDF digital signature, you need a digital ID. You can create a self-signed digital ID using [Adobe Reader](https://helpx.adobe.com/acrobat/using/digital-ids.html#create_a_self_signed_digital_id). The digital ID contains a private key and certificates with a public key.

You can follow these four steps to sign an existing PDF document using Syncfusion PDF Library:

1. Load the existing PDF document.
2. Load the digital ID with password.
3. Create a signature with loaded digital ID (this involves signing the PDF, as well).
4. Save the PDF document.

The following code example shows how to add a digital signature to an existing PDF file.

```csharp
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
class Program
{
    static void Main(string[] args)
    {
        //Load existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("PDF_Succinctly.pdf");
 
        //Load digital ID with password.
        PdfCertificate certificate = new PdfCertificate(@"DigitalSignatureTest.pfx", "DigitalPass123");
 
        //Create a signature with loaded digital ID.
        PdfSignature signature = new PdfSignature(document, document.Pages[0], certificate, "DigitalSignature");
 
        //Save the PDF document.
        document.Save("SignedDocument.pdf");
 
        //Close the document.
        document.Close(true);
    }
}
```

By executing this code example, you will get a PDF document similar to the following screenshot.

![Digitally signed PDF document—Syncfusion PDF Library](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/Digitally-signed-PDF-document%E2%80%94Syncfusion-PDF-Library.png)<figcaption>Digitally signed PDF document—Syncfusion PDF Library</figcaption>

To get a valid green tick in your Adobe Acrobat Reader, as seen in the previous screenshot, you will have to [register](https://helpx.adobe.com/acrobat/using/digital-ids.html#register_a_digital_id) the self-signed digital ID into the trusted source.

Otherwise, to get a valid signature in any Adobe Acrobat Reader, your digital ID should be an [AATL-enabled signing credential](https://helpx.adobe.com/acrobat/kb/approved-trust-list2.html#HowdoIgetanAATLenabledsigningcredential).

## PDF digital signatures with custom appearances

To create a visible digital signature, you must set the bounds to the signature. You can also customize the appearance of the signature using the **Appearance** property available in the class **PdfSignature**. You can draw any shape, text, and image for the signature appearance.

The following code example shows how to add a visible digital signature to a PDF document with a custom appearance.

```csharp
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
class Program
{
    static void Main(string[] args)
    {
        //Load existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("PDF_Succinctly.pdf");
 
        //Load digital ID with password.
        PdfCertificate certificate = new PdfCertificate(@"DigitalSignatureTest.pfx", "DigitalPass123");
 
        //Create a signature with loaded digital ID.
        PdfSignature signature = new PdfSignature(document, document.Pages[0], certificate, "DigitalSignature");
        //Set bounds to the signature.
signature.Bounds = new System.Drawing.RectangleF(40, 40, 350, 100);
 
        //Load image from file.
        PdfImage image = PdfImage.FromFile("signature.png");
        //Create a font to draw text.
        PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 15);
 
        //Drawing text, shape, and image into the signature appearance.
signature.Appearance.Normal.Graphics.DrawRectangle(PdfPens.Black,PdfBrushes.White, new System.Drawing.RectangleF(50, 0, 300, 100));
        signature.Appearance.Normal.Graphics.DrawImage(image, 0, 0,100,100);
signature.Appearance.Normal.Graphics.DrawString("Digitally Signed by Syncfusion", font,PdfBrushes.Black, 120, 17);
        signature.Appearance.Normal.Graphics.DrawString("Reason: Testing signature", font, PdfBrushes.Black, 120, 39);
        signature.Appearance.Normal.Graphics.DrawString("Location: USA", font, PdfBrushes.Black, 120, 60);
 
        //Save the PDF document.
        document.Save("SignedAppearance.pdf");
 
        //Close the document.
        document.Close(true);
    }
}
```

By executing this code example, you will get a PDF document similar to the following screenshot.

![Appearance customized PDF digital signature—Syncfusion PDF Library](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/Appearance-customized-PDF-digital-signature%E2%80%94Syncfusion-PDF-Library.png)<figcaption>Appearance customized PDF digital signature—Syncfusion PDF Library</figcaption>

## Digital signatures with CAdES and different hashing algorithms

By default, the Syncfusion PDF Library generates digital signatures with CMS (part 2 of the PAdES) standard and SHA 256 hashing algorithm.

You can change the digital signature standard to CAdES (part 3 of the PAdES) using the property **CryptographicStandard** available in the class **PdfSignatureSettings**. It also has the property **DigestAlgorithm** to change the hashing algorithm.

The following code example shows how to add a digital signature with CAdES standard with a different hashing algorithm.

```csharp
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
class Program
{
    static void Main(string[] args)
    {
        //Load existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("PDF_Succinctly.pdf");
 
        //Load digital ID with password.
        PdfCertificate certificate = new PdfCertificate(@"DigitalSignatureTest.pfx", "DigitalPass123");
 
        //Create a signature with loaded digital ID.
        PdfSignature signature = new PdfSignature(document, document.Pages[0], certificate, "DigitalSignature");
 
        //Changing the digital signature standard and hashing algorithm.
        signature.Settings.CryptographicStandard = CryptographicStandard.CADES;
        signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA512;
 
        //Save the PDF document.
        document.Save("SigneCAdES.pdf");
 
        //Close the document.
        document.Close(true);
    }
}
```

By executing this code example, you will get a PDF document with the following digital signature properties.

![Digital signature properties in a PDF document](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/Digital-signature-properties-in-a-PDF-document.png)<figcaption>Digital signature properties in a PDF document</figcaption>

## Adding multiple digital signatures in a single PDF document

You can add multiple digital signatures in a single PDF document by appending additional signatures to an already-signed PDF file.

In the following sample, we have added the first digital signature using the digital ID “TestAgreement.pfx”. This is called the first revision.

The second revision contains the digital signature with digital ID “DigitalSignatureTest.pfx”.

```csharp
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
class Program
{
    static void Main(string[] args)
    {
        //Load existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("PDF_Succinctly.pdf");
 
        //Load digital ID with password.
        PdfCertificate certificate = new PdfCertificate(@"TestAgreement.pfx", "Test123");
 
        //Create a Revision 2 signature with loaded digital ID.
        PdfSignature signature = new PdfSignature(document, document.Pages[0], certificate, "DigitalSignature1");
 
        //Changing the digital signature standard and hashing algorithm.
        signature.Settings.CryptographicStandard = CryptographicStandard.CADES;
        signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA512;
 
        MemoryStream stream = new MemoryStream();
 
        //Save the PDF document.
        document.Save(stream);
 
        //Close the document.
        document.Close(true);
 
 
        PdfLoadedDocument document2 = new PdfLoadedDocument(stream);
        //Load digital ID with password.
        PdfCertificate certificate2 = new PdfCertificate(@"DigitalSignatureTest.pfx", "DigitalPass123");
 
        //Create a signature Revision 2 with loaded digital ID.
        PdfSignature signature2 = new PdfSignature(document2, document2.Pages[0], certificate2, "DigitalSignature2");
 
        //Changing the digital signature standard and hashing algorithm.
        signature2.Settings.CryptographicStandard = CryptographicStandard.CADES;
        signature2.Settings.DigestAlgorithm = DigestAlgorithm.SHA512;
 
        //Save the PDF document.
        document2.Save("MultipleSignature.pdf");
 
        //Close the document.
        document2.Close(true);
    }
}
```

By executing this code example, you will get a PDF document with two digital signatures.

![PDF document with more than one digital signature](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/PDF-document-with-more-than-one-digital-signature.png)<figcaption>PDF document with more than one digital signature</figcaption>

## Digitally sign a PDF document using Windows certificate store

A secure way to store the digital ID is using the Windows certificate store. You can retrieve the digital ID “X509Certificate2” from the Windows certificate store and use it to add a digital signature to a PDF document.

The following code example shows how to add a digital signature using the Windows certificate store.

```csharp
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
using System.Security.Cryptography.X509Certificates;
 
class Program
{
    static void Main(string[] args)
    {
        //Initialize the Windows store.
        X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
        store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
        X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
        //Find the certificate using thumb print.
        X509Certificate2Collection fcollection = (X509Certificate2Collection)collection.Find(X509FindType.FindByThumbprint, "F85E1C5D93115CA3F969DA3ABC8E0E9547FCCF5A", true);
        X509Certificate2 digitalID = collection[0];
 
        //Load existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("PDF_Succinctly.pdf");
 
        //Load X509Certificate2.
        PdfCertificate certificate = new PdfCertificate(digitalID);
 
        //Create a Revision 2 signature with loaded digital ID.
        PdfSignature signature = new PdfSignature(document, document.Pages[0], certificate, "DigitalSignature");
 
        //Changing the digital signature standard and hashing algorithm.
        signature.Settings.CryptographicStandard = CryptographicStandard.CADES;
        signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA512;
 
        //Save the PDF document.
        document.Save("WindowsStore.pdf");
 
        //Close the document.
        document.Close(true);
 
    }
}
```

By executing this code example, you will get a PDF document similar to the following screenshot.

![PDF document digitally signed using Windows certificate store](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/PDF-document-digitally-signed-using-Windows-certificate-store.png)<figcaption>PDF document digitally signed using Windows certificate store</figcaption>

## Digitally sign a PDF document with an external signature

The PDF Library allows you to sign PDF documents with an external digital signature created from various sources such as HSM, USB tokens, and smart cards, or other cloud services such as DigiSign.

The following code example shows how to sign a PDF document using an external signature.

```csharp
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.Pkcs;
using System.Security.Cryptography.X509Certificates;
 
class Program
{
    static void Main(string[] args)
    {
 
        //Load existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("PDF_Succinctly.pdf");
 
        //Create a Revision 2 signature with loaded digital ID.
        PdfSignature signature = new PdfSignature(document, document.Pages[0], null, "DigitalSignature");
        signature.ComputeHash += Signature_ComputeHash;
 
        //Save the PDF document.
        document.Save("ExternalSignature.pdf");
 
        //Close the document.
        document.Close(true);
 
        void Signature_ComputeHash(object sender, PdfSignatureEventArgs arguments)
        {
            //Get the document bytes.
            byte[] documentBytes = arguments.Data;
 
            SignedCms signedCms = new SignedCms(new ContentInfo(documentBytes), detached: true);
            //Compute the signature using the specified digital ID file and the password.
            X509Certificate2 certificate = new X509Certificate2("DigitalSignatureTest.pfx", "DigitalPass123");
            var cmsSigner = new CmsSigner(certificate);
            //Set the digest algorithm SHA256.
            cmsSigner.DigestAlgorithm = new Oid("2.16.840.1.101.3.4.2.1");
            signedCms.ComputeSignature(cmsSigner);
            //Embed the encoded digital signature to the PDF document.
            arguments.SignedData = signedCms.Encode();
        }
    }
}
```

By executing this code example, you will get a PDF document similar to the following screenshot.

![PDF document digitally signed with external source](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/PDF-document-digitally-signed-with-external-source.png)<figcaption>PDF document digitally signed with external source</figcaption>

## Digitally sign existing signature field in a PDF document

You can load the signature field from an existing PDF document and sign the field using the following code example.

```csharp
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
class Program
{
    static void Main(string[] args)
    {
        //Load existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("PDF_SignField.pdf");
 
        //Get the first page of the document.
        PdfLoadedPage page = document.Pages[0] as PdfLoadedPage;
 
        //Gets the first signature field from the PDF document.
        PdfLoadedSignatureField field = document.Form.Fields[0] as PdfLoadedSignatureField;
 
        //Load digital ID with password.
        PdfCertificate certificate = new PdfCertificate("DigitalSignatureTest.pfx", "DigitalPass123");
 
        field.Signature = new PdfSignature(document, page, certificate, "Signature", field);
 
        //Get graphics from form field.
        PdfGraphics graphics = field.Signature.Appearance.Normal.Graphics;
        //Load image from file.
        PdfImage image = PdfImage.FromFile("signature.png");
        //Create a font to draw text.
        PdfStandardFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 15);
 
        //Drawing text, shape, and image into the signature appearance.
        graphics.DrawRectangle(PdfPens.Black, PdfBrushes.White, new System.Drawing.RectangleF(50, 0, field.Bounds.Width-50, field.Bounds.Height));
        graphics.DrawImage(image, 0, 0, 100, field.Bounds.Height);
        graphics.DrawString("Digitally Signed by Syncfusion", font, PdfBrushes.Black, 120, 17);
        graphics.DrawString("Reason: Testing signature", font, PdfBrushes.Black, 120, 39);
        graphics.DrawString("Location: USA", font, PdfBrushes.Black, 120, 60);
 
        //Saves the document.
        document.Save("SignedField.pdf");
        //Closes the document.
        document.Close(true);
    }
}
```

To create a signature field, please refer to the following UG documentation link.

[https://help.syncfusion.com/file-formats/pdf/working-with-forms#adding-the-signature-field](https://help.syncfusion.com/file-formats/pdf/working-with-forms#adding-the-signature-field)

By executing this code example, you will get a PDF document similar to the following screenshot.

![PDF digital signature included at the signature field](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/PDF-digital-signature-included-at-the-signature-field.png)<figcaption>PDF digital signature included at the signature field</figcaption>

## Add timestamp to the digital signature

A digital timestamp is used to create a PDF signature with the secure time and date as proof of integrity.

You can digitally sign a PDF with a secure timestamp by referring to the following code example.

```csharp
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
class Program
{
    static void Main(string[] args)
    {
        //Load existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("PDF_Succinctly.pdf");
 
        //Load digital ID with password.
        PdfCertificate certificate = new PdfCertificate(@"DigitalSignatureTest.pfx", "DigitalPass123");
 
        //Create a signature with loaded digital ID.
        PdfSignature signature = new PdfSignature(document, document.Pages[0], certificate, "DigitalSignature");
 
        //Changing the digital signature standard and hashing algorithm.
        signature.Settings.CryptographicStandard = CryptographicStandard.CADES;
     
 
     
        signature.TimeStampServer = new TimeStampServer(new Uri("http://timestamp.digicert.com/"));
 
        //Save the PDF document.
        document.Save("SignedTimestamp.pdf");
 
        //Close the document.
        document.Close(true);
    }
}
```

By executing this code example, you will get the PDF document with following information.

![Time stamp details in the PDF digital signature](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/Time-stamp-details-in-the-PDF-digital-signature.png)<figcaption>Time stamp details in the PDF digital signature</figcaption>

## Retrieving digital signature information from an existing PDF document.

Using Syncfusion PDF Library, you can retrieve the digital signature information, such as issuer name, validity, and digest algorithm, from an existing PDF document.

The following code example shows how to retrieve digital signature information from an existing PDF document.

```csharp
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
class Program
{
    static void Main(string[] args)
    {
        //Load an existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("SignedAppearance.pdf");
 
        //Get the signature field from PdfLoadedDocument form field collection.
        PdfLoadedSignatureField signatureField = document.Form.Fields[0] as PdfLoadedSignatureField;
        PdfSignature signature = signatureField.Signature;
 
        //Extract the signature information.
        Console.WriteLine("Digitally Signed by: " + signature.Certificate.IssuerName);
        Console.WriteLine("Valid From: " + signature.Certificate.ValidFrom);
        Console.WriteLine("Valid To: " + signature.Certificate.ValidTo);
        Console.WriteLine("Hash Algorithm : " + signature.Settings.DigestAlgorithm);
        Console.WriteLine("Cryptographics Standard : " + signature.Settings.CryptographicStandard);
 
        //Close the document
        document.Close(true);
    }
}
```

## Remove existing digital signatures from a PDF document

You can remove a digital signature from a PDF document using the following code example.

```csharp
using Syncfusion.Pdf.Parsing;
class Program
{
    static void Main(string[] args)
    {
        //Load an existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("SignedAppearance.pdf");
 
        //Get the signature field from PdfloadedDocument form field collection.
        PdfLoadedSignatureField signatureField = document.Form.Fields[0] as PdfLoadedSignatureField;
        //Remove signature field from PdfLoadedDocument form field collection.
        document.Form.Fields.Remove(signatureField);
 
        //Save the PDF document.
        document.Save("RemoveDigital.pdf");
        document.Close(true);
    }
}
```

By executing this code example, you will get a PDF document like the following.

![Digital signature removed from the PDF document](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/Digital-signature-removed-from-the-PDF-document.png)<figcaption>Digital signature removed from the PDF document</figcaption>

## Validate PDF digital signature

To ensure the authenticity and integrity of the PDF document, you must validate the digital signature present in it.

The PDF Library has an API to validate digital signatures. You can validate the digital signatures in any number of PDF documents without human interaction.

Digital signature validation covers following steps to ensure validity:

1. Validate the document modification.
2. Validate the certificate chain.
3. Ensure the signature with timestamp time.
4. Check the revocation status of the certificate with OCSP and CRL.
5. Ensure multiple digital signatures.

The following code example shows how to validate all the digital signatures present in a PDF document.

```csharp
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
class Program
{
    static void Main(string[] args)
    {
        //Load an existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("MultipleSignature.pdf");
        //Load PDF form.
        PdfLoadedForm form = document.Form;
 
        List results;
 
        if (form != null)
        {   
            //Validate all the digital signatures present in the PDF document.
            bool isValid = form.Fields.ValidateSignatures(out results);
 
            //Show the result based on the result.
            if (isValid)
                Console.WriteLine("All signatures are valid");
            else
                Console.WriteLine("At least one signature is invalid");
        }
        //Close the document.
        document.Close(true);
    }
}
```

The previous code example will iterate and validate all the digital signatures present in the PDF document. If any one of the digital signatures is invalid, then the result will be **false**. You can also get the validation results of the individual signatures.

The **PdfSignatureValidationResult** contains information about each digital signature and its status. We will see more details in upcoming topics.

### Validate individual digital signatures in an existing PDF document

Syncfusion PDF Library allows you to iterate and validate individual digital signatures in an existing PDF document. The following code shows how to validate individual digital signatures.

```csharp
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
class Program
{
    static void Main(string[] args)
    {
        //Load an existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("MultipleSignature.pdf");
        //Load PDF form.
        PdfLoadedForm form = document.Form;
 
        if (form != null)
        {
            foreach (PdfLoadedField field in form.Fields)
            {
                if (field is PdfLoadedSignatureField)
                {
                    PdfLoadedSignatureField signatureField = field as PdfLoadedSignatureField;
 
                    //Check whether the signature is signed.
                    if (signatureField.IsSigned)
                    {
                        //Validate the digital signature.
                        PdfSignatureValidationResult result = signatureField.ValidateSignature();
 
                        if (result.IsSignatureValid)
                            Console.WriteLine("Signature is valid");
                        else
                            Console.WriteLine("Signature is invalid");
 
                        //Retrieve the signature information.
                        Console.WriteLine("<<<<>>>>>>");
                        Console.WriteLine("Digitally Signed by: " + signatureField.Signature.Certificate.IssuerName);
                        Console.WriteLine("Valid From: " + signatureField.Signature.Certificate.ValidFrom);
                        Console.WriteLine("Valid To: " + signatureField.Signature.Certificate.ValidTo);
                        Console.WriteLine("Signature Algorithm : " + result.SignatureAlgorithm);
                        Console.WriteLine("Hash Algorithm : " + result.DigestAlgorithm);
                        Console.WriteLine("Cryptographics Standard : " + result.CryptographicStandard);
                        Console.Read();
                    }
                }
            }
        }
    }
}
```

By executing this code example, you will get a PDF document with information similar to the following screenshot.

![Validating PDF digital signatures](https://www.syncfusion.com/blogs/wp-content/uploads/2019/10/Validating-PDF-digital-signatures.png)<figcaption>Validating PDF digital signatures</figcaption>

### Validating signatures against a trusted list

You can create and pass your own trusted list of certificates to validate a digital signature in a PDF document.

The following example shows how to load a local Windows certificate store and validate the digital signature against the Window certificate store.

```csharp
using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
using System.Security.Cryptography.X509Certificates;
class Program
{
    static void Main(string[] args)
    {
        //Load an existing PDF document.
        PdfLoadedDocument document = new PdfLoadedDocument("MultipleSignature.pdf");
        //Load PDF form.
        PdfLoadedForm form = document.Form;
 
        //Load Windows certificate store.
        X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
        store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
        X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
 
        if (form != null)
        {
            foreach (PdfLoadedField field in form.Fields)
            {
                if (field is PdfLoadedSignatureField)
                {
                    PdfLoadedSignatureField signatureField = field as PdfLoadedSignatureField;
 
                    //Validate the digital signature against Windows certificate store.
                    PdfSignatureValidationResult result = signatureField.ValidateSignature(collection);
 
                    if (result.IsSignatureValid)
                        Console.WriteLine("Signature is valid");
                    else
                        Console.WriteLine("Signature is invalid");
 
                    //Update the signatures status based on the certificate validation against certificate store.
                    Console.WriteLine("Signature status: " + result.SignatureStatus);
                }
            }
        }
    }
}
```

## Conclusion

In this blog post, we have walked through how PDF digital signatures work and the functionality of Syncfusion PDF Library in PDF digital signature creation and validation.

So, now you can easily include PDF digital signatures and validate them in your development process with Syncfusion PDF Library.

Take a moment to peruse our [documentation](https://help.syncfusion.com/file-formats/pdf/working-with-digitalsignature), where you’ll find other options and features, all with accompanying code examples.

If you have any questions about these features, please let us know in the comments below. You can also contact us through our [support forum](https://www.syncfusion.com/forums), [Direct-Trac](https://www.syncfusion.com/support/directtrac/?_ga=2.203813140.507257297.1548648173-2146943073.1535695045), or [feedback portal](https://www.syncfusion.com/feedback/pdf). We are happy to assist you!

If you like this article, we think you would also like the following articles about PDF Library:

- [How to Find Corrupted PDF Files in C# Easily](https://dev.to/syncfusion/how-to-find-corrupted-pdf-files-in-c-easily-16hi)
- [How to Convert an Image to PDF in ASP.NET Core](https://www.syncfusion.com/blogs/post/how-to-convert-image-to-pdf-in-asp-net-core.aspx)
- [Easy Ways to Redact PDFs Using C#](https://www.syncfusion.com/blogs/post/easy-ways-to-redact-pdfs-using-c.aspx)
- [7 Ways to Compress PDF Files in C#, VB.NET](https://www.syncfusion.com/blogs/post/7-ways-to-compress-pdf-files.aspx)

The post [How to Digitally Sign and Verify PDF Documents in C# (PDF 2.0 Update)](https://www.syncfusion.com/blogs/post/digitally-sign-and-verify-pdf-documents-csharp.aspx) appeared first on [Syncfusion Blogs](https://www.syncfusion.com/blogs).