Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Aug 09, 2022 3:37 pm

Hello,

we would like to sign PDF documents with a certificate using the ECDSA algorithm. Loading the certificate works fine, but on saving the document (pdf.SaveToFile) we get a System.NotSupportedException with message "The certificate key algorithm is not supported.".

In short the PrivateKey property on X509Certificate2 is not supported for elliptic curve algorithms (and also marked obsolete with .NET 6). The specific method GetECDsaPrivateKey (or GetRSAPrivateKey, ...) must be used.

Is there any way to still sign a PDF with this certificate using Spire.PDF?

Thanks,
Philip

philiphoyer
 
Posts: 1
Joined: Mon Aug 08, 2022 4:44 pm

Wed Aug 10, 2022 8:33 am

Hi Philip,

I'm sorry that Spire.PDF does not currently support ECDSA certificates. If you have any other questions about our products, please feel free to contact us.
Sincerely,
Andy
E-iceblue support team
User avatar

Andy.Zhou
 
Posts: 483
Joined: Mon Mar 29, 2021 3:03 am

Thu Jun 15, 2023 9:29 am

You can create your own class (e.g.) EcdsaSignature based on IPdfSignatureFormatter interface and put this in the Sign method:

var cert = Certificate you got from parameter in constructor;
var dsa = new WpkiDsa(cert);
var cmsSigner = new CmsSigner(SubjectIdentifierType.IssuerAndSerialNumber, cert, dsa);
SignedCms signedCms = new SignedCms(new ContentInfo(content), true);
signedCms.ComputeSignature(cmsSigner, true);
return signedCms.Encode();

Create new class for your new AsymmetricAlgorithm:
class WpkiDsa : ECDsa
send certificate in constructor and use it in this method to calculate the signature with private key:
public override byte[] SignHash(byte[] hash)

Use
var signature = new PdfSignature(doc, page, EcdsaSignature, "signature");
Note: Sign is called twice, first time to check signature length

tonchek8
 
Posts: 2
Joined: Mon May 22, 2023 12:19 pm

Return to Spire.PDF