Не могу загрузить сертификат пользователя в веб-сборке (веб-приложение Blazor).
Вот мой код (это модифицированный пример «Начало работы с Blazor»).
...added strings to _ViewImports.cshtml:
@using System.Security.Cryptography;
@using System.Security.Cryptography.X509Certificates;
@using System.Security;
...
@page "/counter"
<h1>Counter</h1>
<p>Current count: @currentCount</p>
<p>Cert Name: @cname</p>
<button class="btn btn-primary" onclick="@IncrementCount">Click me</button>
@functions {
int currentCount = 0;
string cname = "";
public X509Certificate2 UserCert;
void IncrementCount()
{
currentCount++;
UserCert = selectCert();
cname = UserCert?.GetNameInfo(X509NameType.SimpleName, false);
}
public X509Certificate2 selectCert()
{
X509Certificate2 certSelected = null;
try
{
X509Store x509Store = new X509Store("MY", StoreLocation.CurrentUser);
x509Store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection col = x509Store.Certificates;
X509Certificate2Collection fcollection = (X509Certificate2Collection)col.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
if (fcollection.Count > 0)
{
certSelected = fcollection[0];
}
x509Store.Close();
}
catch (Exception ex)
{
cname = ex.Message;
}
return certSelected;
}
}
Но происходит сбой с сообщением об исключении «Магазин МОЕ не существует» или что-то в этом роде. Итак, я просто хочу получить доступ к хранилищу пользовательских сертификатов для создания цифровых подписей и т. Д. Как я могу это сделать? Спасибо.