【问题标题】:cryptographic exception unhandled in creating certificate创建证书时未处理的加密异常
【发布时间】:2013-02-06 06:55:51
【问题描述】:

我正在创建这个简单的控制台应用程序,它将创建我自己的证书。这是我的代码。

var fi = new FileInfo("certificate.cer");
if (!fi.Exists)
{
  var startInfo = new ProcessStartInfo();
  startInfo.FileName = "makecert.exe";
  startInfo.Arguments = "-sv SignRoot.pvk -cy authority -r sha1 -n \"CN=Certificate\" -ss my -sr localmachine certificate.cer";
  Process.Start(startInfo);
}
X509Certificate.CreateFromCertFile("certificate.cer");

但为什么我在最后一行代码中得到了这个?

CryptographicException was unhandled.
Message=The system cannot find the file specified.

【问题讨论】:

    标签: c# .net cryptography x509certificate makecert


    【解决方案1】:

    您需要等待makecert进程退出后才能使用证书。

     Process
        .Start(startInfo)
        .WaitForExit();
    

    【讨论】:

      【解决方案2】:

      我通过使用批处理(.bat)文件解决了这种情况,因为我发现它更容易。并让c#在程序启动时运行批处理文件。谢谢您的帮助。 :)

      【讨论】:

        猜你喜欢
        • 2013-03-20
        • 2017-03-29
        • 1970-01-01
        • 2023-03-07
        • 2011-02-11
        • 2018-07-02
        • 2014-03-11
        • 2021-01-26
        • 1970-01-01
        相关资源
        最近更新 更多