我有使用Pluralsight.Crypto
库创建自签名证书的服务。从昨天开始,我收到以下错误,而且我不知道如何解决。
错误消息: 该系统找不到指定的文件。 (来自HRESULT的异常:0x80070002)
来源:mscorlib
这是我的代码
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);
我在crypto.Open()
上获得了代码。