Pluralsight crypto open context 0x80070002 error

0

I have service that creates a self signed certificate using Pluralsight.Crypto library. Since yesterday i'm getting following error and i don't know how to fix it.

Error Message: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

Source: mscorlib

Here is my code

  var fileName = "myCertificate";
  var pfxPass = toolService.GetRandomPassword();

  var certificateProps = new SelfSignedCertProperties
  {
    IsPrivateKeyExportable = true,
    KeyBitLength = 4096,
    Name = new X500DistinguishedName($"CN={fileName}"),
    ValidFrom = DateTime.Now,
    ValidTo = DateTime.Now.AddYears(60)
  };

  X509Certificate2 certificate;
  using (var crypto = new CryptContext())
  {
    crypto.Open();
    certificate = crypto.CreateSelfSignedCertificate(certificateProps);
  }

  var pfx = certificate.Export(X509ContentType.Pfx, pfxPass);
  var cer = certificate.Export(X509ContentType.Cert);

I get the code on crypto.Open().

c#
certificate
self-signed

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0