Search code examples
c#.netcryptographyx509certificatemakecert

cryptographic exception unhandled in creating certificate


I am creating this simple console application that will create my own certificate. Here's my code.

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");

But why am i getting this on my last line of code?

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

Solution

  • I resolved the situation by using a batch(.bat) file, because I find it easier. And let c# run the batch file when the program starts. Thanks for the help. :)