Digitally sign a PDF using iTextSharp 4.1.6.0 without keys exportable certificate

0

I tried to sign pdf using itextshapr 4.1.6 in c# as per way provided in https://web.archive.org/web/20130329022247/http://itextpdf.sourceforge.net/howtosign.html

I followed the steps given in link: Digitally sign a PDF using iTextSharp 4.1.6.0

Section : "How to sign with an external signature dictionary using BouncyCastle CMS"

CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
generator.addSigner(key, (X509Certificate)chain[0], CMSSignedDataGenerator.DIGEST_SHA1);

I am getting below exception while getting privatekey:

System.Security.Cryptography.CryptographicException
HResult=0x8009000B
Message=Key not valid for use in specified state.

Source=mscorlib
StackTrace:
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.Utils._ExportKey(SafeKeyHandle hKey, Int32 blobType, Object cspObject)
at System.Security.Cryptography.RSACryptoServiceProvider.ExportParameters(Boolean includePrivateParameters)
at Org.BouncyCastle.Security.DotNetUtilities.GetKeyPair(AsymmetricAlgorithm privateKey)
at ITextSharpDemo.IItextSharp416Tester.Main(String[] args) in D:\Projects\IAS\trunk\SourceCode\Demo\ITextSharpDemo4.1.6\ITextSharpDemo\IItextSharp416Tester.cs:line 70

It requires certificate to be installed with keys exportable. We are able to sign pdf after reinstalling certificate with keys exportable.

What to do if certificate is not installed with keys exportable? We need to work with itextsharp 4.1.6 version.

pdf
itext
digital-signature
asked on Stack Overflow Apr 13, 2021 by DeveloperPDF

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0