pdf - 使用 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 版本。
解决方案
推荐阅读
- twitter-bootstrap-3 - Boostrap 3 - 缩略图对齐问题
- java - 用于启动 Java Spring Boot 项目的 curl 命令
- javascript - 具有多个 IF 条件的 Google Apps 脚本
- react-native - 如何使用 TouchableOpacity 在 React Native 中隐藏视图?
- python - 使用 PYTHON 将一列数字作为第一列添加到已存在的带有数字的 TEXT 文件中
- android - 来自移动设备的 REACT Fetch 请求不起作用
- r - 错误:`n()` 只能在 dplyr 动词中使用,甚至不能在我的代码中使用 n()
- python - 如何捕获内部 TensorFlow 错误:python 中的“GPU 同步失败”?
- javascript - 尝试播放音频时出现“无法读取未定义的属性‘添加’”
- java - 致命错误编译:无效的目标版本:在推送到 heroku 期间为 11