.net - 登录iTextSharp时如何自动输入密码
问题描述
我必须使用存储在安全令牌中的证书。我可以从 Windows 证书存储区访问它,但设备有密码,因此会显示一个带有输入字段的弹出窗口,我使用CspParameters作为自动输入密码。
但是,当我签署数千个文件时,弹出的输入密码再次出现。这是我用来加载证书的代码:
public X509Certificate2 loadX509byPass()
{
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.MaxAllowed);
var certificates = store.Certificates.Find(X509FindType.FindBySerialNumber, SerialNumber, false);
var cert = certificates[0];
store.Close();
var pass = new SecureString();
char[] array = Password.ToCharArray();
foreach (char ch in array)
{
pass.AppendChar(ch);
}
var privateKey = cert.PrivateKey as RSACryptoServiceProvider;
CspParameters cspParameters = new CspParameters(privateKey.CspKeyContainerInfo.ProviderType,
privateKey.CspKeyContainerInfo.ProviderName,
privateKey.CspKeyContainerInfo.KeyContainerName,
new System.Security.AccessControl.CryptoKeySecurity(),
pass);
var rsaCsp = new RSACryptoServiceProvider(cspParameters);
// set modified RSA crypto provider back
cert.PrivateKey = rsaCsp;
return cert;
}
当签署文件时:
Cert = SingletonCA.Instance.loadX509byPass();
....
BcX509.X509Certificate bcCert = DotNetUtils.FromX509Certificate(Cert);
var chain = new List<BcX509.X509Certificate> { bcCert };
var FontColour = new BaseColor(0, 0, 255);
IExternalSignature pks = new X509Certificate2Signature(Cert, "SHA1");
MakeSignature.SignDetached(appearance, pks, chain, null, null, null, 0, CryptoStandard.CMS);
是否可以在代码中发送密码以不显示此消息?
谢谢你的帮助。
解决方案
推荐阅读
- javascript - 有没有办法使用 InboxSDK 拦截 Gmail 撰写窗口的发送按钮?
- c# - 是否可以在瀑布对话框中设置带有日期输入的自适应卡片?(在 Web 和团队上使用 Bot Framework)
- docker - 使用 https 时的 Traefik 错误网关
- google-apps-script - 谷歌电子表格脚本显示了一些奇怪的行为
- linux - 如何获取文件中的特定数据并将其输出定向到新文件?
- c# - 我如何创建一个字符串数组并使其可用于我们的 C# 控制台应用程序中的所有方法
- python - 在函数中解包列表但在使用 MAP() 完成时不需要?
- python - Python - 计算列表中项目列表的出现次数?
- swift - 在 UINavigationBar 中的 searchBar isHidden 后取回标题
- python - 在 python 中拟合 digamma 函数时出错