1
如何确保C#代码使用password
来使用certificate's private key
?证书安装在CurrentUser/Personal
商店中。我试过,但仍然我的代码使用私钥而不提示输入密码。使用X509Certificate2执行数字签名提示输入密码以使用私钥
byte[] fileData = File.ReadAllBytes(path);
ContentInfo contentInfo = new ContentInfo(fileData);
SignedCms signedCms =
new SignedCms(SubjectIdentifierType.SubjectKeyIdentifier, contentInfo, true);
CmsSigner signer =
new CmsSigner(SubjectIdentifierType.SubjectKeyIdentifier, MyLoadedCert);
signer.IncludeOption = X509IncludeOption.WholeChain;
signedCms.ComputeSignature(signer); // Works fine without prompting password
byte[] encoded = signedCms.Encode();
File.WriteAllBytes(signatureFilePath, encoded);
它不抛出任何为我破例。但是如果我把'signedCms.ComputeSignature(signer,false)',那么它会在外部窗口中提示输入密码。为什么在静音模式下它不起作用?我的证书中是否需要某些东西? –
@GokulE它是恕我直言静默模式=不允许用户交互。我没有在.NET中找到任何方式来检查一个证书是否具有强大的密钥保护,但也许我只是 看起来不够硬:) – pepo