using System.Security.Cryptography.X509Certificates; X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadOnly); X509Certificate2Collection certs = store.Certificates; foreach (X509Certificate2 cert in certs) { Console.WriteLine(cert.SubjectName.Name); } store.Close();
using System.Security.Cryptography.X509Certificates; X509Certificate2 cert = new X509Certificate2("certificate.pfx", "password"); X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); store.Add(cert); store.Close();In this example, we create an instance of the X509Certificate2 class, passing in the path to a certificate file ("certificate.pfx") and its password. We then create an instance of the X509Store class, specifying the store name and location, and open the store in read-write mode. We add the certificate to the store using the Add method, and then close the store. Package library: System.Security.Cryptography.X509Certificates is a part of the .NET framework.