将 signedCms 与智能卡证书一起使用时出错

Error when using signedCms with smartcard certificate

我正在将智能卡证书从用户存储发送到 CmsSigner 的构造函数,以便使用智能卡对 PKCS 加密进行签名。 我在 IIS 7.5 的 Web 应用程序中收到一条错误消息 "Provider could not perform the action since the context was acquired as silent."。 这在 IIS 6.0 With Impersonation 中运行良好。 我在 IIS 7.5 中使用了模拟,但结果是一样的。

在同一台机器和同一电子令牌上使用 Windows 表单应用程序时效果很好。我正在使用 Aladin 电子令牌。

ContentInfo contentInfo = new ContentInfo(msg);
SignedCms signedCms = new SignedCms(contentInfo, false);

CmsSigner cmsSigner = new CmsSigner(signerCert);

cmsSigner.SignedAttributes.Add(new Pkcs9SigningTime());  
signedCms.ComputeSignature(cmsSigner);

经过一些 Google 我发现了同样的问题 Here 。 但是没有人回答。

任何帮助将不胜感激。

提前致谢

当我尝试使用智能卡签署数据并且这张卡受 PIN 保护时,我遇到了同样的错误。

而不是

signedCms.ComputeSignature(cmsSigner);

我用过

signedCms.ComputeSignature(cmsSigner, false);

调用此方法后,显示 PIN 提示 window。我写了 PIN 并且签名成功。

我的问题是没有授予适当的权限,所以我在 IIS 服务器中将应用程序池的标识从 ApplicationPoolIdentity 更改为 LocalService 帐户,一切正常。