Как программно импортировать закрытый ключ в хранилище ключей на локальном компьютере?
На самом деле я тестирую этот код:
private static void InstallCertificate(string certificatePath, string certificatePassword, StoreName store) {
try {
var serviceRuntimeUserCertificateStore = new X509Store(store, StoreLocation.LocalMachine);
serviceRuntimeUserCertificateStore.Open(OpenFlags.ReadWrite);
X509Certificate2 cert;
try {
cert = new X509Certificate2(certificatePath, certificatePassword);
} catch(Exception ex) {
Console.WriteLine("Failed to load certificate " + certificatePath);
throw new DataException("Certificate appeared to load successfully but also seems to be null.", ex);
}
serviceRuntimeUserCertificateStore.Add(cert);
serviceRuntimeUserCertificateStore.Close();
} catch(Exception) {
Console.WriteLine("Failed to install {0}. Check the certificate index entry and verify the certificate file exists.", certificatePath);
}
}
Все попытки получить токен NetworkService не удалось.Код здесь не работает с правами администратора.
Приведенный выше код импортирует закрытый ключ в текущий пользовательский экземпляр локальной машины.Что мне делать?