Sign a PDF with an ECDSA certificate in C#
Elliptic Curve Digital Signature Algorithm (ECDSA) certificates create compact digital signatures with elliptic-curve keys. Nutrient .NET SDK supports ECDSA signing certificates in PDF signing workflows.
Use this workflow when your certificate authority or enterprise policy issues ECDSA document-signing certificates.
This guide shows how to:
- Load an ECDSA certificate from a P12/PFX file
- Configure PDF signature metadata
- Sign a PDF with the ECDSA certificate
This sample expects an ECDSA P12/PFX file named ecdsa-certificate.pfx. The repository sample certificate is RSA-based, so replace it with an ECDSA certificate before running this sample.
Prepare the project
Register the SDK license before running signing operations. For setup details, refer to the getting started with .NET SDK guide.
using System;using GdPicture14;
void CheckStatus(GdPictureStatus status, string operation){ if (status != GdPictureStatus.OK) { throw new InvalidOperationException($"{operation} failed. Status: {status}"); }}
LicenseManager license = new LicenseManager();license.RegisterKEY(""); // Set your license keyLoad the PDF document
Create a GdPicturePDF instance and load the source file:
using GdPicturePDF pdf = new GdPicturePDF();
CheckStatus(pdf.LoadFromFile(@"input.pdf", false), "LoadFromFile");Configure the ECDSA certificate
Load the ECDSA certificate and private key from a P12/PFX file:
CheckStatus(pdf.SetSignatureCertificateFromP12(@"ecdsa-certificate.pfx", "changeit"), "SetSignatureCertificateFromP12");The certificate has to include an ECDSA private key and key usages suitable for document signing.
Configure signature metadata and options
Set signature metadata, hash algorithm, and PAdES baseline level:
CheckStatus(pdf.SetSignatureInfo("Nutrient", "ECDSA PDF signature", "Toulouse", "sales@nutrient.io"), "SetSignatureInfo");CheckStatus(pdf.SetSignatureHash(PdfSignatureHash.SHA256), "SetSignatureHash");CheckStatus(pdf.SetSignaturePAdESLevel(PdfSignaturePAdESLevel.PAdESBaselineB), "SetSignaturePAdESLevel");Apply the ECDSA signature
Create the signed PDF:
CheckStatus(pdf.ApplySignature(@"signed-ecdsa.pdf", PdfSignatureMode.PdfSignatureModeAdobeCADES, true), "ApplySignature");The SDK detects the ECDSA private key from the certificate and writes the signature in the form required for CMS/PAdES.
Error handling
Check every GdPictureStatus value. Certificate errors usually indicate an incorrect password, a missing private key, unsupported key usage, or a certificate that doesn’t use an ECDSA key.
Conclusion
This workflow signs a PDF with an ECDSA certificate loaded from a P12/PFX file.