首页 > 解决方案 > 使用 iTextSharp 4.1.6.0 对 PDF 进行数字签名,无需密钥可导出证书

问题描述

我尝试按照https://web.archive.org/web/20130329022247/http://itextpdf.sourceforge.net/howtosign.html中提供的方式在 c# 中使用 itextshapr 4.1.6 签署 pdf

我按照链接中给出的步骤操作: 使用 iTextSharp 4.1.6.0 对 PDF 进行数字签名

部分:“如何使用 BouncyCastle CMS 使用外部签名字典进行签名”

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

我在获取私钥时遇到异常:

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

它需要使用可导出的密钥安装证书。我们可以在重新安装带有可导出密钥的证书后签署 pdf。

如果证书没有安装可导出的密钥怎么办?我们需要使用 itextsharp 4.1.6 版本。

标签: pdfitextdigital-signature

解决方案


推荐阅读