Код: Выделить всё
X509Certificate2 cert = ToCertificate("CN=localhost");
public static X509Certificate2 ToCertificate(this string subjectName,
StoreName name = StoreName.My,
StoreLocation location = StoreLocation.LocalMachine
)
{
X509Store store = new X509Store(name, location);
store.Open(OpenFlags.ReadOnly);
try
{
var cert = store.Certificates.OfType().FirstOrDefault(c => c.Subject.Equals(subjectName, StringComparison.OrdinalIgnoreCase));
return cert != null ? new X509Certificate2(cert) : null;
}
catch (Exception)
{
throw;
}
finally
{
store.Certificates.OfType().ToList().ForEach(c => c.Reset());
store.Close();
}
}
Код: Выделить всё
PrivateKey = 'cert.PrivateKey' threw an exception of type 'System.Security.Cryptography.CryptographicException'

Я попробовал это исправление и это исправление
Но проблема все равно осталась!
Подробнее здесь: https://stackoverflow.com/questions/450 ... ptographic