Articles in this section
Category / Section

How to digitally sign PDF document with CAdES using C# and VB.NET in WinForms?

2 mins read

The Syncfusion Essential PDF is a feature rich and high-performance .NET PDF library used to create, read, and edit PDF documents programmatically without Adobe dependencies. This library also offers functionality to merge, split, stamp, forms, compress, and secure PDF files.

As per the PDF specification 2.0, now Syncfusion PDF library supports digital signature based on CAdES (CMS Advanced Electronics Signature). The CAdES based digital signature can remain valid for long periods, even if underlying cryptographic algorithms are broken.

Steps to digitally sign PDF document with CAdES programmatically in C#:

  1. Create a new C# console application project.

Create a console application in Visual Studio

  1. Install the Syncfusion.Pdf.WinForms NuGet package as reference to your .NET framework application from NuGet.org. Refer NuGet to the project
  2. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf.Interactive; 
using Syncfusion.Pdf.Security;

 

VB.NET

Imports Syncfusion.Pdf.Interactive
Imports Syncfusion.Pdf.Security;

4.    You can change the digital signature standard to CAdES using the property “CryptographicStandard”

        available in the class “PdfSignatureSettings”. The following code example explains how to digitally 

       sign a PDF document with CAdES.

C#

//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");
 
//Chaning the digital singature standard and hashing algorithm
signature.Settings.CryptographicStandard = CryptographicStandard.CADES;
signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA512;
 
//Save the PDF document
document.Save("SignCAdES.pdf");
 
//Close the document
document.Close(true);
 

 

VB.NET

'Load existing PDF document
Dim document As PdfLoadedDocument = New PdfLoadedDocument("PDF_Succinctly.pdf")
'Load Digital ID with password
Dim certificate As PdfCertificate = New PdfCertificate("DigitalSignatureTest.pfx", "DigitalPass123")
'Create a signature with loaded Digital ID
Dim signature As PdfSignature = New PdfSignature(document, document.Pages(0), certificate, "DigitalSignature")
'Chaning the digital singature standard
signature.Settings.CryptographicStandard = CryptographicStandard.CADES
signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA512;
 
'Save the PDF document
document.Save("SignCAdES.pdf")
'Close the document
document.Close(True)

 

A complete working sample can be downloaded from CreateDigitalSignatureSample.Zip.

By executing the program, you will get the PDF document as follows.

Digitally sign document with CAdES

Take a moment to peruse the documentation, where you will find other options like digitally sign a pdf file, digitally sign an existing pdf document ,remove the digital signature from an existing pdf document, and more with code examples.

Click here to explore the rich set of Syncfusion Essential PDF features.

See Also:

Digital signature and timestamp pdf

Note:

Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

 

 

Conclusion

I hope you enjoyed learning about how to digitally sign PDF document with CAdES using C# and VB.NET.

You can refer to our WinForms PDF feature tour
page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms PDF example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please  to leave a comment
Access denied
Access denied