How to Digitally Sign PDF with Cades Using C# and VB.NET in WinForms?
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, the Syncfusion® PDF library now supports digital signatures based on CAdES (CMS Advanced Electronic Signature). The CAdES-based digital signature can remain valid for long periods, even if the underlying cryptographic algorithms are broken.
Steps to digitally sign a PDF document with CAdES programmatically in C#:
- Create a new C# console application project.
- Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET framework application from NuGet.org.
- 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");
// Changing the digital signature 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")
'Changing the digital signature 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.
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.
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.
Conclusion
I hope you enjoyed learning about how to digitally sign PDFs with CAdES using C# and VB.NET in WinForms.
You can refer to our WinForms PDF feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our WinForms PDF examples 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 forums or feedback portal. We are always happy to assist you!