Раньше эти сертификаты хранились в помощнике, который извлекал их с локального компьютера, как показано в следующем примере:
Код: Выделить всё
public static class X509Certificate2Helper
{
private static readonly X509Store x509Store = new X509Store(StoreLocation.LocalMachine);
public static X509Certificate2 FindByFriendlyName(string certificateName)
{
ArgumentException.ThrowIfNullOrWhiteSpace(certificateName);
var certificate = Find(collection => collection.FirstOrDefault(c => c.FriendlyName == certificateName));
return certificate;
}
public static X509Certificate2 FindByThumbprint(string thumbprint)
{
ArgumentException.ThrowIfNullOrWhiteSpace(thumbprint);
var certificate = Find(certificates => certificates.Find(X509FindType.FindByThumbprint, thumbprint, false)
.FirstOrDefault());
return certificate;
}
private static X509Certificate2 Find(Func func)
{
x509Store.Open(OpenFlags.ReadOnly);
var certificates = x509Store.Certificates;
x509Store.Close();
var certificate = func(certificates);
if (certificate == null)
{
throw new InvalidOperationException("Certificate not found");
}
return certificate;
}
}
Я бы хотел избежать использования внедрения методов для клиента следующим образом:
Код: Выделить всё
public static X509Certificate2 FindByFriendlyName(string certificateName, CertificateClient client)
Подробнее здесь: https://stackoverflow.com/questions/793 ... atic-class
Мобильная версия